我改造了一下做的爬取微博評(píng)論的腳本效果如" />

国产成人精品无码青草_亚洲国产美女精品久久久久∴_欧美人与鲁交大毛片免费_国产果冻豆传媒麻婆精东

15158846557 在線咨詢 在線咨詢
15158846557 在線咨詢
所在位置: 首頁(yè) > 營(yíng)銷資訊 > 網(wǎng)站運(yùn)營(yíng) > Python 爬蟲如何機(jī)器登錄新浪微博并抓取內(nèi)容?

Python 爬蟲如何機(jī)器登錄新浪微博并抓取內(nèi)容?

時(shí)間:2023-11-22 11:12:01 | 來(lái)源:網(wǎng)站運(yùn)營(yíng)

時(shí)間:2023-11-22 11:12:01 來(lái)源:網(wǎng)站運(yùn)營(yíng)

Python 爬蟲如何機(jī)器登錄新浪微博并抓取內(nèi)容?:前段時(shí)間在研究sina和twitter的數(shù)據(jù),很久之前寫得一個(gè)模擬登陸的腳本沒(méi)用了,于是朋友給我發(fā)了一份有用的模擬登陸腳本,親測(cè)有效。

我改造了一下做的爬取微博評(píng)論的腳本效果如下:

下面是代碼,結(jié)合以下代碼理解一下,希望對(duì)你有用。

# -*- coding: utf-8 -*- import requests import base64 import re import urllibimport urllib.parseimport rsa import json import binascii from bs4 import BeautifulSoup class Userlogin: def userlogin(self,username,password,pagecount): session = requests.Session() url_prelogin = 'http://login.sina.com.cn/sso/prelogin.php?entry=weibo&callback=sinaSSOController.preloginCallBack&su=&rsakt=mod&client=ssologin.js(v1.4.5)&_=1364875106625' url_login = 'http://login.sina.com.cn/sso/login.php?client=ssologin.js(v1.4.5)' #get servertime,nonce, pubkey,rsakv resp = session.get(url_prelogin) json_data = re.findall(r'(?<=/().*(?=/))', resp.text)[0] data = json.loads(json_data) servertime = data['servertime'] nonce = data['nonce'] pubkey = data['pubkey'] rsakv = data['rsakv'] # calculate su print(urllib.parse.quote(username)) su = base64.b64encode(username.encode(encoding="utf-8")) #calculate sp rsaPublickey= int(pubkey,16) key = rsa.PublicKey(rsaPublickey,65537) message = str(servertime) +'/t' + str(nonce) + '/n' + str(password) sp = binascii.b2a_hex(rsa.encrypt(message.encode(encoding="utf-8"),key)) postdata = { 'entry': 'weibo', 'gateway': '1', 'from': '', 'savestate': '7', 'userticket': '1', 'ssosimplelogin': '1', 'vsnf': '1', 'vsnval': '', 'su': su, 'service': 'miniblog', 'servertime': servertime, 'nonce': nonce, 'pwencode': 'rsa2', 'sp': sp, 'encoding': 'UTF-8', 'url': 'http://weibo.com/ajaxlogin.php?framelogin=1&callback=parent.sinaSSOController.feedBackUrlCallBack', 'returntype': 'META', 'rsakv' : rsakv, } resp = session.post(url_login,data=postdata) # print resp.headers print(resp.content) login_url = re.findall(r'http://weibo.*&retcode=0',resp.text) # print(login_url) respo = session.get(login_url[0]) uid = re.findall('"uniqueid":"(/d+)",',respo.text)[0] url = "http://weibo.com/u/"+uid respo = session.get(url)

關(guān)鍵詞:內(nèi)容,爬蟲,機(jī)器

74
73
25
news

版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。

為了最佳展示效果,本站不支持IE9及以下版本的瀏覽器,建議您使用谷歌Chrome瀏覽器。 點(diǎn)擊下載Chrome瀏覽器
關(guān)閉