python 抓取, 根據cookie

#coding=utf8

import urllib2
import re

"""
Login to Sina Weibo with cookie
"""

COOKIE = '' #fill with your weibo.com cookie
HEADERS = {"cookie": COOKIE}

def test_login():
    url = 'http://weibo.com'
    req = urllib2.Request(url, headers=HEADERS)
    text = urllib2.urlopen(req).read()

    pat_title = re.compile('<title>(.+?)</title>')
    r = pat_title.search(text)
    if r:
        print r.group(1)


if __name__ == '__main__':
    test_login()

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章