标签:jpg mozilla chrome rom htm url head sys enc
#编码流程:
#1.验证码的识别,获取验证码图片的文字数据
#2.对post请求进行发送(处理请求函数)
#3.对响应函数进行持久化存储
import requests
from lxml import etree
from CodeClass import YDMHttp
#创建一个session对象
session = requests.Session()
#1.对验证码图片进行捕获和识别
headers = {
‘User-Agent‘:‘Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2626.106 Safari/537.36‘
}
url = ‘http://www.renren.com/SysHome.do‘
page_text = requests.get(url=url,headers=headers).text
tree = etree.HTML(page_text)
code_img_src = etree.xpath(‘//*[@id="verifyPic_login"]/@src‘)[0]
code_img_data = requests.get(url=code_img_src,headers=headers).content
with open(‘./code.jpg‘,‘wb‘) as fp:
fp.write(code_img_data)
#使用云打码提供的示例代码对验证码图片进行识别
result = getCodeText(‘code.jpg‘,2004)
#post请求的发送(模拟登录)
login_url = ‘‘
data = {
}
#使用session进行post请求的发送
response = session.post(url=login_url,headers=headers,data=data)
print(response.status_code)
#爬取当前用户个人主页对应的页面数据
detail_url = ‘http://www.renren.com/974813621/profile‘
# headers = {
# ‘Cookie‘:‘xxxx‘
# }
#使用携带cookie的session进行get请求发送
detail_page_test = session.get(url=detail_url,headers=headers).text
with open(‘./bob.html‘,‘w‘,encoding=‘utf-8‘) as fp:
fp.write(detail_page_text)
标签:jpg mozilla chrome rom htm url head sys enc
原文地址:https://www.cnblogs.com/gerenboke/p/13389054.html