from yue.aaa.tuozhan_all import post, get
import json
from urllib import request, parse
#导入包 ,保存cookie
from http import cookiejar
#通过对象保存cookie
cookie = cookiejar.CookieJar()
#handler 对应着一个操作
handler = request.HTTPCookieProcessor(cookie)
# opener 遇到有cookie的response的时候,调用handler内的一个函数 存储cookie到 objec中
opener = request.build_opener(handler)
# 1.url
url = 'http://www.renren.com/ajaxLogin/login?1=1&uniqueTimestamp=2018722359875'
# 2. form
form = {
'email': '17600015762',
'icode': '',
'origURL': 'http://www.renren.com/home',
'domain': 'renren.com',
'key_id': '1',
'captcha_type': 'web_login',
'password': '000e2c3c99f8a73a61287bcaaa16d53f11dea4f308438ff687eb64c557a14962',
'rkey': 'ccfaa6b14a7da2899fccd0a15cbd7b13',
'f': '',
}
# 3.调用函数 post
form_bytes = parse.urlencode(form).encode('utf-8')
# response = request.urlopen(url,form_bytes)
# opener = response.build_opener()
# opener.open()
response = opener.open(url,form_bytes)
html_byte = response.read()
# html_byte = post(url,form = form)
#3 .打印结果
# print(html_byte)
res_dict = json.loads(html_byte.decode('utf-8'))
home_url = res_dict['homeUrl']
#访问页面
response = opener.open(home_url)
html_byte =response.read()
print(html_byte.decode('utf-8'))
爬虫--人人网-简易爬取2
最新推荐文章于 2021-11-12 20:05:46 发布