首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python-Twitter API

Python-Twitter API
EN

Stack Overflow用户
提问于 2017-06-02 12:04:47
回答 1查看 186关注 0票数 0

我想知道有没有办法不用他们的API就能抓取twitter?我试着使用他们的API,它很棒。不过,我想问一问,是否有其他选择?由于我正在处理的爬虫将被传递,我不希望我的令牌密钥在它们之间共享。我也不希望他们每个人都经历创建Dev帐户的麻烦,诸如此类。

我用twitter API创建的爬虫能够检索很多很多tweet。而我创建的爬虫只能爬行10条左右,因为其他tweet会在html之外。

我使用的是python 3.6

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2017-06-02 12:18:59

是一种在不使用twitter API的情况下爬行/ scrape twitter的方法;但是,强烈建议您使用API本身的。这有几个优点,比如it是官方的,另外还有来自社区的大量支持。

不过,您可以使用requestsbeautiful soup执行爬行,或者如果您正在寻找更强大的选项,请使用SeleniumPhantomJS

这里有几个类似的问题,你可以通读一下:

Scraping of the Twitter follower page using selenium and phantomjs

How to collect tweets about an event that are posted on specific date using python?

How to perform oauth when doing twitter scraping with python requests

Infinite Web Scraping Twitter

干杯:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44320591

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档