【发布时间】:2018-08-08 00:31:57
【问题描述】:
我正在做一个项目来抓取多个 twitter URL 并将他们的关注者数量分配给 csv:
username= ['LazadaPH','ZALORAPH','ShopeePH','eBayPhilippines','beauty_MNL']
for user in username:
url = 'https://www.twitter.com/'+ user
r = requests.get(url)
soup = BeautifulSoup(r.content,'lxml')
f = soup.find('li', class_="ProfileNav-item--followers")
title = f.find('a')['title']
num_followers = int(title.split(' ')[0].replace(',',''))
print(user,num_followers)
输出如下:
LazadaPH 52841
ZALORAPH 29786
ShopeePH 7004
eBayPhilippines 874
beauty_MNL 2469
由于我对 python 很陌生(并且不希望提出多余的问题):但是有人可以指导我获取有关如何将此打印输出分配给 csv 并将其提取为两个的资源和教程列(第 1 列是网站字符串,第 2 列是关注者数量)。
有什么建议吗?
非常感谢!
【问题讨论】:
-
要求我们推荐或查找书籍、工具、软件库、教程或其他场外资源的问题对于 Stack Overflow 来说是无关紧要的,因为它们往往会吸引固执己见的答案和垃圾邮件。相反,describe the problem 以及迄今为止为解决它所做的工作。
-
有很多关于输出结果到 csv 的帖子,例如this
标签: python csv twitter beautifulsoup screen-scraping