网页抓取与BeautifulSoup找不到任何东西 [英] Web scraping with beautifulsoup not finding anything

查看:127
本文介绍了网页抓取与BeautifulSoup找不到任何东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图抓取coinmarketcap.com,以获取某个货币价格的更新,还只是为了学习如何通过网络抓取.我仍然是一个初学者,无法弄清楚哪里出了问题,因为每当我尝试运行它时,它只会告诉我没有错误.虽然我知道那条线确实存在.感谢您的帮助!

I'm trying to scrape coinmarketcap.com just to get an update of a certain currency price, also just to learn how to web scrape. I'm still a beginner and can't figure out where I'm going wrong, because whenever I try to run it, it just tells me there are none. Although I know that line does exist. Any help is appreciated!

import requests
from bs4 import BeautifulSoup

url = 'https://coinmarketcap.com/currencies/electroneum/'
response = requests.get(url)
html = response.content

soup = BeautifulSoup(html, 'html.parser')
price = soup.find('data-currency-price data-usd=')
print (price)

推荐答案

您可以使用class属性获取值.

You can use the class attribute to get the value.

import requests
from bs4 import BeautifulSoup

url = 'https://coinmarketcap.com/currencies/electroneum/'
response = requests.get(url)
html = response.content

soup = BeautifulSoup(html, 'html.parser')
price = soup.find('span' ,attrs={"class" : "h2 text-semi-bold details-panel-item--price__value"})
print (price.text)

输出:

0.006778

这篇关于网页抓取与BeautifulSoup找不到任何东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆