Web Scraping返回空值

时间:2018-01-10 18:05:50

标签: python-3.x web-scraping tweepy

我是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)

1 个答案:

答案 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类搜索