您的位置:首页 > 其它

模拟登陆新浪微博【直接填入Cookie】(转)

2016-04-23 17:03 267 查看
转自:

https://www.douban.com/note/264976536/

1.获取cookie

方法

2.将cookie作为参数提交

""" Simulate a user login to Sina Weibo with cookie.
You can use this method to visit any page that requires login.
"""

import urllib2
import re

cookie = 'your key'  # get your cookie from Chrome or Firefox
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0',
'cookie': cookie
}

def visit():
url = 'http://douban.com'
req = urllib2.Request(url, headers=headers)
text = urllib2.urlopen(req).read()

# print the title, check if you login to weibo sucessfully
pat_title = re.compile('<title>(.+?)</title>')
r = pat_title.search(text)
if r:
print r.group(1)
#print text

if __name__ == '__main__':
visit()


学习学习~ 谢谢博主
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: