S
S
Sergey2017-08-29 21:08:29
Python
Sergey, 2017-08-29 21:08:29

Why doesn't output by id with Beautiful Soup?

I made such a script, but it does not output anything at all! To display a value by id.
Tell a newbie!

import requests
from bs4 import BeautifulSoup

page = requests.get("https://blockchain.info/ru/stats")
soup = BeautifulSoup(page.content, 'html.parser')
soup.select("td#market_price_usd")

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Ranc58, 2017-08-29
@alekskondr

All the information you need goes through the API
. You can understand this by opening Chrome dev-tools, network tab, XHR tab. Reload the page and see this: 9bc01abc205b4c40b520853a67ffebe5.png
Looks like the data you're looking for. Go to the headers tab, there will be a link to the API (I already gave it to you above).
As a result, you don’t need to parse anything, just pull the information from the API. For good, always when you think of something from where to pull - check the site for the presence of the API.

A
Astrohas, 2017-08-29
@Astrohas

soup.find("td", {"id": "market_price_usd"})

D
Dmitry, 2017-08-29
@LazyTalent

1.select returns a list
2. to see the content of the tag, you must use the method get_text()
3. According to your link, the given cell is empty and does not contain any content

soup = BeautifulSoup(page.content, 'html.parser')
td_content = soup.select("td#market_price_usd")[0].get_text()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question