首页 > 代码库 > Cookies 模拟登录

Cookies 模拟登录

#coding=utf-8

import requests
from lxml import etree
from multiprocessing.dummy import Pool

cook={"Cookie":"your cookies"}
url =http://weibo.cn/u/uid

#html=requests.get(url).content
#print html

html=requests.get(url,cookies=cook).content

#html=requests.get(url,cookies=cook).text
#html=bytes(bytearray(html,encoding=‘utf-8‘))

selector = etree.HTML(html)
content =selector.xpath(//span[@class="ctt"])
for each in content:
    text=each.xpath(string(.))
    b = 1
    print text

运行结果:
技术分享

 

方法一:

html=requests.get(url,cookies=cook).content

方法二:

html=requests.get(url,cookies=cook).text
html=bytes(bytearray(html,encoding=utf-8))

 

极客课程--定向爬虫:简单的模拟登录   http://www.jikexueyuan.com/course/995.html

核心内容:

1.Fiddler 的介绍和使用

2.Fiddler 抓取分析数据包

3.已知 Cookies 登录新浪微博

4.Requests 模拟登录

 

Cookies 模拟登录