【问题标题】:Web scrape Weibo Follower count using python使用 python 抓取微博关注者数量
【发布时间】:2016-05-18 09:28:55
【问题描述】:

您好我是python的初学者,我正在尝试获取一些微博帐户的关注者数量。我尝试使用微博 API,但无法获取微博帐户的信息(不是我的帐户/没有凭据)。据我查到,微博要求用户提交申请以供审核,以获取更多API(包括获取关注者数)

因此,我决定尝试使用网页抓取,而不是使用微博 API。但是,我对此并没有太多想法。我知道我可以使用 json 和 requests 之类的库来从网站获取内容。我坚持获取内容

from json import loads
import requests
username_weibo = ['kupono','xxx','etc']

def get_weibo_followers(username):
    output = ['Followers']
    for user in username:
        r = requests.get('https://www.weibo.com/'+user).content
        html = r.encode('utf-8')

    return r

到目前为止,我试图打印出代码的样子,而我得到的是一堆乱七八糟的单词/字符。另外,FM.views(来自页面源)太多,让我很困惑。

这是我到目前为止所做的,但我不知道如何继续。有人可以帮忙吗?谢谢。

【问题讨论】:

    标签: python weibo


    【解决方案1】:

    嗨,我是 python 和英语的初学者 :)。我也在做同样的事情,昨天完成了。你看到的微博页面是由浏览器中的脚本创建的。您可以从脚本中提取everysing,例如“FM.view( ....”) 图书馆重新。

    登录后,您可以这样做:

    import re
    from urllib import parse
    reponse = session.get('http://weibo.com/u/xxxxxxxxx')
    #xxxxxxx is the account's ID.    
    html_raw_data = parse.unquote(reponse.content.decode())
    #url decode
    html_data = re.sub(r'\\'r'',html_raw_data)
    #backslash has Escaped two times,get the raw code
    follows_fans_articles_data = re.search(r'\[\'page_id\'\]=\'(\d+)',html_data,re.M)
    #follows_fans_articles_data.group(1)  follows number    (2)  fans number  (3) articles number
    

    【讨论】:

      猜你喜欢
      • 2016-02-04
      • 1970-01-01
      • 1970-01-01
      • 2022-01-16
      • 1970-01-01
      • 1970-01-01
      • 2021-03-23
      • 1970-01-01
      • 2013-07-01
      相关资源
      最近更新 更多