> For the complete documentation index, see [llms.txt](https://openup.gitbook.io/training-content/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://openup.gitbook.io/training-content/procurement-data-crash-course/module-2-working-with-procurement-data/2.2-turning-websites-and-pdfs-into-machine-readable-data/web-scraping-by-inspecting-network-traffic.md).

# Web scraping by inspecting network traffic

How to scrape data from South African E-Tender portal

As discussed in previous lessons, [tender notices and supporting documents](/training-content/procurement-data-crash-course/module-1-how-the-public-procurement-process-works/1.3-where-is-public-procurement-data-published/where-to-find-procurement-data.md) issued by public bodies should be added to the central [E-Tender portal run by national government](https://www.etenders.gov.za/). The data uploaded here is hard to work with, partly because it is incomplete - many important pieces of information are stored in attached documents rather than in the site database - and you cannot easily download it for analysis.&#x20;

In this topic, we will show you how address the second of those challenges, by scraping data from the website using its own search query URLs.

There's some terminology to understand.&#x20;

* **Application Programming Interface (API)** An API is used when two software applications want to talk to each other. In this case, the API connects your web browser to the E-Tenders database. Database search queries are passed over as that part of the URL in your browser's address bar which follows the **question mark**.
* **JavaScript Object Notation (JSON)** Data is passed from the database to your browser in response to an API query, in a data format known as JSON. JSON is a little bit similar to a [CSV](/training-content/procurement-data-crash-course/module-2-working-with-procurement-data/2.1-whey-we-need-machine-readable-data/important-data-formats-csvs-excel-and-google-sheets.md) file, but with data arranged in a different format so as to allow more flexibility.

### Step 1: Visit the  E-Tender portal

Open the E-Tender portal <https://www.etenders.gov.za/> , and click **browse opportunities**.

Notice there are four categories to choose from, **Currently Advertised**, **Awarded**, **Closed** and **Cancelled** tenders.

![](https://3925319274-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuSSbOeqjFMxbM6oPQFVO%2Fuploads%2FLq42vHLXhOyqQjoK5PGU%2FScreenshot\(70\).png?alt=media\&token=00f57008-9733-43f2-964c-b38e1d2a0b98)

What if you wanted to create a list of all currently advertised tenders which you can import to your spreadsheet software to analyse?

### Step 2: Find the API links

If you click on Currently Advertised, you should see a table appear in the middle of the page with tender information. This data is populated by an API call, and we can find the specific link by pressing **F12** to open up our browser **Inspect** function.

You can also hover your mouse over the table, right-click and select Inspect.

In the Inspect window, click on the Network tab. Your screen should look something like this.

![](https://3925319274-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuSSbOeqjFMxbM6oPQFVO%2Fuploads%2FlhReMTXn5PQHYtmk6epP%2Ff12.png?alt=media\&token=4a4d3d0d-09e9-4bf3-8693-f9adbcec85a5)

You may need to reload the page at this point.&#x20;

Now click the *Fetch/XHR* button to filter the output of this screen, then click on the result. You should see the API request being sent to collect data.

![](https://3925319274-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuSSbOeqjFMxbM6oPQFVO%2Fuploads%2FQtNNrQdXYQ14nrlqkU1P%2Fxhr.png?alt=media\&token=256167a6-f625-4213-8d58-e6fbbd7cf978)

Double click on the result under **Name.** This should start ***?status=1&\_=***  and finish with a long number that represents the last record. It will take you to the URL that’s returning data. When you open this in a new browser tab, you should see something like this.&#x20;

![](https://3925319274-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuSSbOeqjFMxbM6oPQFVO%2Fuploads%2FmY6RRaOkMsRYtBDairOM%2Furl.png?alt=media\&token=2e2c9e6b-1ce6-4eb2-b9fe-044e41552074)

This is the JSON output that is sent in response to the API request. Here are examples of the API requests at the time of writing.

* **Currently advertised**

<https://www.etenders.gov.za/Home/TenderOpportunities/?status=1&_=1654507040789>

* **Awarded**

<https://www.etenders.gov.za/Home/TenderOpportunities/?status=2&_=1654507040789>

* **Closed**

<https://www.etenders.gov.za/Home/TenderOpportunities/?status=3&_=1654507040789>

* **Cancelled**

<https://www.etenders.gov.za/Home/TenderOpportunities/?status=4&_=1654507040789>

### Step 3: Getting the JSON into a spreadsheet

Once you have the JSON data in your browser, you can save it onto your local machine., Just right click and choose **Save** in the menu. Save as “your\_name.json”

![](https://3925319274-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuSSbOeqjFMxbM6oPQFVO%2Fuploads%2FILgTttK8nEPOMCKnT3Dv%2Fsave.png?alt=media\&token=876c1a68-095b-495b-9a49-c739763a7c75)

Spreadsheet software can't read JSON files directly, however, so next you'll need to convert this data to a CSV file. Our favourite too for this conversion is <https://csvjson.com/>.&#x20;

![, click browse file to upload the json file that you just saved, wait for it to upload](https://3925319274-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuSSbOeqjFMxbM6oPQFVO%2Fuploads%2FJba0outeG38P244G6e6e%2Fjson_csv.png?alt=media\&token=99287775-d702-4fe8-b8dc-c1ebe725889f)

Click **JSON to CSV** then upload the file you just created, then click **Convert**.

![lick download, you get the csv file of all the currently advertising tender](https://3925319274-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuSSbOeqjFMxbM6oPQFVO%2Fuploads%2FYOdxCMQmulDEin1rvYcI%2Fupload.png?alt=media\&token=8cae1551-6890-4f37-b77f-58abea1dbae3)

After the conversion has taken place, you'll be able to select download to save the CSV file on your desktop.

![](https://3925319274-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuSSbOeqjFMxbM6oPQFVO%2Fuploads%2FuGzFMWk8jb2xvjiBm7Jc%2Fconvert.png?alt=media\&token=54053e2c-e959-4c86-94eb-8fab2de3cfcc)

### Step 4: Import the data to Google Sheets

Importing a CSV into Google Sheets is easy. Create a new spreadsheet and call it **Currently Advertised**. Now, under the **File** menu, choose **Import**, select your CSV file then **Replace Current Sheet** and finally **Import data**.

![](https://3925319274-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuSSbOeqjFMxbM6oPQFVO%2Fuploads%2FlUBYXCGtrD2zXPT5uJOm%2Fopen_googlesheet.png?alt=media\&token=efabf7ef-f255-466f-9620-63c0714e4052)

Now you have a spreadsheet with the details of all currently open tenders on the E-Tender portal, including department name, contact details and a brief description. You can do the same for closed, cancelled and awarded tenders too.

![](https://3925319274-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuSSbOeqjFMxbM6oPQFVO%2Fuploads%2FKRGBvFSqMIFH1QhjqrhW%2Fimage.png?alt=media\&token=b8027169-a044-4ce7-8b7d-a1988bedf63c)&#x20;
