# Web scraping by inspecting network traffic

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.

![](/files/NrwGmZkPpqkaqFHJ3gUN)

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.

![](/files/LX9NA2vAmO8cTnmJEpNA)

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.

![](/files/cIaWNdUwJCeVbBV1t4Cu)

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;

![](/files/7DBXU0tBnm2EH559k4BB)

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”

![](/files/oRI1uVi6P4O73ukAXVcX)

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](/files/nuMoZB1GpkUtQYkKnZcL)

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](/files/bOD47rmSx2iOOOE5kZkL)

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

![](/files/VdRWYvPEGLkwWNJe3awQ)

### 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**.

![](/files/eiHtwCZsOInqLxqZBeDb)

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.

![](/files/zguMRg7IiwtCxWXoKdAX)&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET 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?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
