python(三)2 User Agent

一.

import urllib2


if __name__ == '__main__' :

    

    url = 'http://www.csdn.net'

    head ={}

    head['User-Agent'] = 'Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19'

    

    req = urllib2.Request(url,headers=head)

    response = urllib2.urlopen(req)

    html = response.read().decode('utf-8')

    print html


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