Web 抓取微博粉丝数使用 python
Web scrape Weibo Follower count using 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
我试图打印出到目前为止代码的样子,但我得到的是一堆乱七八糟的 words/characters。另外还有太多FM.views(来自page source)让我很困惑。
这是我到目前为止所做的,但我不知道如何继续。有人可以帮忙吗?谢谢。
嗨,我是 python 和英语的初学者 :)。我也在做同样的事情,昨天就完成了。你看到的微博页面是由浏览器中的脚本创建的。您可以从 "FM.view( ...." 之类的脚本中提取 everysing
图书馆重新
登录后,您可以这样做:
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
您好,我是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
我试图打印出到目前为止代码的样子,但我得到的是一堆乱七八糟的 words/characters。另外还有太多FM.views(来自page source)让我很困惑。
这是我到目前为止所做的,但我不知道如何继续。有人可以帮忙吗?谢谢。
嗨,我是 python 和英语的初学者 :)。我也在做同样的事情,昨天就完成了。你看到的微博页面是由浏览器中的脚本创建的。您可以从 "FM.view( ...." 之类的脚本中提取 everysing 图书馆重新
登录后,您可以这样做:
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