Why is the html viewed through developer tools different from the html fetched through beautifulsoup?

Viewed 102

Hi i am making a program that scrapes jobs from stackoverflow accordingly when i enter a specific keyword.

To do that, I need to know the maximum number of pages when you enter a specific keyword. However, the html content viewed through the developer tool and the html imported through beautifulsoup are different and are having a problem.

For example, let's call the keyword'vue'.

The url is as follows: https://stackoverflow.com/jobs?q=vue

The number of pages checked through developer tools is 2. enter image description here

However, if you check the number of pages after entering the following code and outputting the result, the maximum number of pages is 43.

from bs4 import BeautifulSoup
import requests
url = "https://stackoverflow.com/jobs?q=vue"
result = requests.get(url)
soup = BeautifulSoup(result.text,"html.parser")
print(soup)

enter image description here

I need to load the content corresponding to 2 pages related to vue, but I am having a problem of scraping not only this content but also unrelated content.

I did not know where the problem occurred, so I asked questions. Any help would be appreciated.

1 Answers

In the request headers there's one called user-agent identifies which program is performing the request. Read more

user-agent in request header

To pretend making a request from the browser, you could try to set the user-agent header to this Chrome User Agent string:

Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
Related