使用python抓取微博粉丝数



嗨,我是python的初学者,我正在努力获得一些微博账户的粉丝数量。我试过使用微博API,但无法获得微博帐户的信息(不是我的帐户/没有证书)。据我所查,微博要求用户提交审核申请,以便访问更多API(包括获得关注人数)

因此,我决定尝试使用网络抓取,而不是使用微博API。然而,我并没有太多这样做的想法。我知道我可以使用json之类的库和请求从网站上获取内容。我很难获得内容

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和英语的初学者:)。我也在做同样的事情,昨天就完成了。您看到的微博页面是通过浏览器中的脚本创建的。你可以通过以下方式从"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

最新更新