#-*-coding:utf8-*-
import requests
from lxml import etree
url = 'http://weibo.cn/u/xxxxxx' #此处请修改为微博地址
url_login = 'https://login.weibo.cn/login/'
html = requests.get(url).content
selector = etree.HTML(html)
####注意以下三个的内容会发生变化,在network中会发现,所以在登陆源码中能够查找到
password = selector.xpath('//input[@type="password"]/@name')[0]
vk = selector.xpath('//input[@name="vk"]/@value')[0]
action = selector.xpath('//form[@method="post"]/@action')[0]
#print action
#print password
#print vk
new_url = url_login + action #登陆请求的网址
data = {
'mobile' : 'xxxx@xxx.com',
password : 'xxxxxxxx', ###变量
'remember' : 'on',
'backURL' : 'http://weibo.cn/u/xxxxx', #此处请填写微博地址
'backTitle' : u'微博',
'tryCount' : '',
'vk' : vk,
'submit' : u'登录'
}
newhtml = requests.post(new_url,data=data).content
new_selector = etree.HTML(newhtml)
# print newhtml.content
content = new_selector.xpath('//span[@class="ctt"]')
for each in content:
text = each.xpath('string(.)')
print textpython爬虫之新浪微博模拟登陆
最新推荐文章于 2024-07-21 22:31:38 发布
本文介绍了一种使用Python爬取微博信息的方法。通过requests库获取网页内容,lxml解析页面结构,实现微博登录及抓取微博上的文本内容。
1028

被折叠的 条评论
为什么被折叠?



