【发布时间】:2017-06-02 04:04:46
【问题描述】:
我想知道是否有方法可以在不使用其 API 的情况下抓取 Twitter?我尝试使用他们的 API,它很棒。不过我想问一下有没有其他选择?由于我正在开发的爬虫将被传递,我不希望我的令牌密钥在它们之间共享。我也不希望他们每个人都经历创建开发帐户的麻烦等等。
我使用 twitter API 创建的爬虫能够检索许多推文。我创建的爬虫只能爬 10 条左右,因为其他推文会在 html 之外。
我正在使用 python 3.6
def spider(targetname, DOMAIN):
for item in g_data:
try:
name = item.find_all("strong", {"class": "fullname show-popup-with-id "})[0].text
username = item.find_all("span", {"class": "username u-dir"})[0].text
post = item.find_all("p", {"class": "TweetTextSize TweetTextSize--normal js-tweet-text tweet-text"})[0].text
retweetby = item.find_all("a", {"href": "/"+targetname})[0].text
subdatas = item.find_all('div', {'class':'ProfileTweet-actionCountList u-hiddenVisually'})
for subdata in subdatas:
replies = subdata.find_all("span", {"class": "ProfileTweet-actionCountForAria"})[0].text
retweets = subdata.find_all("span", {"class": "ProfileTweet-actionCountForAria"})[1].text
likes = subdata.find_all("span", {"class": "ProfileTweet-actionCountForAria"})[2].text
datas = item.find_all('a', {'class':'tweet-timestamp js-permalink js-nav js-tooltip'})
for data in datas:
link = DOMAIN + data['href']
date = data['title']
if link in open(crawledfile).read():
pass
else:
append_to_crawled(crawledfile, name, username, post, link, replies, retweets, likes, retweetby, date)
output(name, username, post, link, replies, retweets, likes, retweetby, date)
except:
pass
【问题讨论】:
-
没办法,绕过twitter的API。
-
在没有 twitter API 的情况下发布你的爬虫的代码
-
@MrSam 很好,你可以使用 Selenium 和 PhantomJS。
-
嗨@TheDarkKnight 我已经发布了正在爬行的部分。介意看看吗?