我是Python的新手。我试图运行网络抓取应用程序。 当我运行下面的python脚本时,我得到空值。请指教。
import bs4
import requests
url2= 'https://bitcoinfees.info/'
res2= requests.get(url)
soup2 = bs4.BeautifulSoup(res2.text,'html.parser')
highfee= soup2.select_one('html.wf-roboto-n5-active.wf-roboto-n4- active.wf-active body div.container ul.list-group li.list-group-item span.badge').text
print(highfee)
答案 0 :(得分:1)
示例中有两个错误。 requests.get(url)
应为(url2)
,然后highfee
中有一堆内容。看起来你只是在寻找第一个span
。在这种情况下,你可以做soup2.select_one('span').text
所以,你们共同拥有
url2= 'https://bitcoinfees.info/'
res2= requests.get(url2)
soup2 = bs4.BeautifulSoup(res2.text,'html.parser')
highfee= soup2.select_one('span').text
print(highfee)
如果您正在寻找不同的范围,则可以使用soup2.find()
,在这种情况下,您正在寻找标记<span class="badge">
您可以使用
soup2.find("span", class_="badge").string
请参阅soup docs按css类搜索