A
A
Andrey Sokolov2020-07-05 22:31:36
Python
Andrey Sokolov, 2020-07-05 22:31:36

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

3 answer(s)
D
Dmitry Link, 2020-07-05
@DmitryLink

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

S
soremix, 2020-07-05
@SoreMix

Use Beautiful Soup

D
datka, 2020-07-06
@datka

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>

And then parse through requests + BeautifulSoup
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)

Documentation to help.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question