【发布时间】:2021-07-02 23:47:58
【问题描述】:
我想通过这段代码刮掉,但我只得到页面中的前 10 个货币,但页面包含 100 个货币,其他 90 个在哪里?
from bs4 import BeautifulSoup as S
import requests
url = 'https://coinmarketcap.com/'
headers = {'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'}
r = requests.get(url,headers=headers)
soup = S(r.content,'html.parser')
price = soup.find_all('td')
for coin in soup.find_all(class_="sc-1teo54s-2 fZIJcI"):
print(coin) ```
【问题讨论】:
-
我建议你使用CoinMarketCap API来获取数据。前 10K 通话是免费的。您抓取数据的方式不稳定,因为每次部署新更改时都会自动生成类名
sc-1teo54s-2 fZIJcI。 -
但是python没有显示所有页面包含有什么问题?
-
您需要先向下滚动到页脚,以便加载所有数据,然后您可以抓取所需的数据。请在下面查看我的答案,如果我帮助了您,请接受:)
标签: python web-scraping beautifulsoup