Answer the question
In order to leave comments, you need to log in
How to get the value from the site?
I'm interested in how to get 1 site value, let's say the number of comments from the page https://habr.com/en/post/442800/ . Please give the code) I can tell you, you need to use the Google Chrome debugger (F12) and point to the number of comments there, you will see the class, but I don’t know how to get data from it in Python ...
Answer the question
In order to leave comments, you need to log in
Hello. The code will not be given here.
First, you get the desired page through requests.get (), then through bs4 you get the text from the desired class. Here are examples: https://python-scripts.com/beautifulsoup-html-parsing
You don't need a debugger. view-source: https://habr.com/ru/post/442800/ in chrome and search
<span class="post-stats__comments-count" title="Читать комментарии">21</span>
import requests
from bs4 import BeautifulSoup
pageURL = "https://habr.com/ru/post/442800/"
req = requests.get(pageURL)
soup = BeautifulSoup(req.content, 'html.parser')
comments = soup.find('span', {'class': 'post-stats__comments-count'}).get_text()
print('Количество комментариев на '+ pageURL + ' : ' +comments)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question