I’am new in web-parsing and I ran into a problem.
I wanna extract number of watching from the site:
enter image description here
I wrote this code for that purpose:
url = 'https://www.kommersant.ru/doc/4638344'
request = requests.get(url)
req = request.text
soup=BeautifulSoup(req, 'html')
abcd = soup.find("div", class_="doc_sharing__body js-social").find("span", class_="sharing")
print(abcd)
But result of this query is "None"
What’s the problem? Please, help!
I try many iterations with different variation of my code (for example):
url = 'https://www.kommersant.ru/doc/4638344'
request = requests.get(url)
req = request.text
soup=BeautifulSoup(req, 'html')
abcd = soup.find_all("span", attr = {'class':'sharing'}
print(abcd)
But I have same result!
2
Answers
I believe that something like this script can help you retrieve the number of views (I am assuming that this number is the one inside the title tag):
Note: Maybe you’ll have to use
.find_all()
, instead of.find()
. In this case, you have to inspect the retrieved results, to check which of them contains the desired title tag.The view count is stored in the
data-article-views=
parameter:Prints: