你好,我是个蟒蛇的初学者,我正试图获得一些微博账号的粉丝数量。我试过使用微博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 (来自页面源)使我感到困惑。
这是我迄今所做的,但我不知道如何继续下去。有人能帮忙吗?谢谢。
发布于 2016-05-28 15:12:48
嗨,我是python和英语的初学者:).I也在做同样的事情,昨天就完成了。你看到的微博页面是由浏览器中的脚本创建的。您可以从"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 numberhttps://stackoverflow.com/questions/37295477
复制相似问题