简体   繁体   中英

Python Beautiful Soup, how to get a content of <script>

I'm trying to get all information of coins from https://www.binance.com/en/

I have a very basic knowledge of HTML

<script nonce="2266e2ddf786c1ef22250edde36dae937ccbbe17">
        __NEXT_DATA__ = {
                    "tickers": {
                        "NULSBNB": {
                            "s": "NULSBNB",
                            "l": "0.13312",
                            "c": "0.13904",
                            "h": "0.16600",
                            "o": "0.13680",
                            "q": 5514.584306,
                            "v": "37908.30000",
                            "qa": "BNB",
                            "ba": "NULS",
                            "bn": "Nuls",
                            "tickSize": "0.00001",
                            "minTrade": 0.1
                        },

Apparently this is the information I need Here's my code:

import requests
import bs4


URL = "https://www.binance.com/"

r = requests.get(url = URL)
soup = bs4.BeautifulSoup(r.text, 'lxml')


contents = soup.find_all(script ='2266e2ddf786c1ef22250edde36dae937ccbbe17')
print(contents)

And it doesn't work. How do I get a information for every coin? I need "s" and "l" most of all

I would face the problem of get a information for every coin in a different way. It can be easy to get the information from Binance API . With one search I found a decent open source package for python. Using for example this with a set of your coin symbols can do the trick.

Note: I have not tested the package, that not supposed to be the answer. Rather than using the API if it's available, so you don't need to scrape.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM