【发布时间】:2020-09-06 04:45:35
【问题描述】:
我正在尝试抓取this page 中的“TWITTER STATS Summary”表。
这是我的代码
rank_page = 'https://socialblade.com/twitter/user/bill%20gates'
request = urllib2.Request(rank_page, headers={'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36'})
page = urllib2.urlopen(request)
soup = BeautifulSoup(page, 'html.parser')
channels = soup.find('div', attrs={'id': 'socialblade-user-content'}).find_all('div', recursive=False)[10:]
for row in channels:
date = row.find('div', attrs={'style': 'width: 80px; float: left;'})
print date
但我在终端中得到None。我只想获取表格中的日期(DATE FOLLOWERS FOLLOWING MEDIA)。我知道如何继续并将它们保存在 excel 中,但我很难找到 div 和文本。感谢您的帮助
【问题讨论】:
-
需要python2吗?
-
你应该升级
-
并不总是可能的,所以问题仍然存在:需要 python 2 吗?
-
python 2 没关系,只要能用就行
标签: python web-scraping beautifulsoup