| |
| |
| from urllib import request |
| import re |
| import os |
| import random |
| |
| |
| |
| agent_one='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1' |
| agent_two='Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20100101 Firefox/6.0' |
| agent_three='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50' |
| agent_four='Opera/9.80 (Windows NT 6.1; U; zh-cn) Presto/2.9.168 Version/11.50' |
| agent_five='Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; Tablet PC 2.0; .NET4.0E)' |
| agent_six='Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; InfoPath.3)' |
| agent_seven='Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB7.0)' |
| agent_eight='Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)' |
| agent_night='Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)' |
| agent_ten='Mozilla/5.0 (Windows; U; Windows NT 6.1; ) AppleWebKit/534.12 (KHTML, like Gecko) Maxthon/3.0 Safari/534.12' |
| agent_eleven='Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E)' |
| agent_twelve='Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E; SE 2.X MetaSr 1.0)' |
| agent_thirteen='Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.33 Safari/534.3 SE 2.X MetaSr 1.0' |
| agent_fourteen='Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E)' |
| agent_fifteen='Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.41 Safari/535.1 QQBrowser/6.9.11079.201' |
| agent_seventeen='Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E) QQBrowser/6.9.11079.201' |
| agent_eighteen='Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)' |
| agent_nineteen='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 UBrowser/4.0.3214.0 Safari/537.36' |
| agent_twenty='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Maxthon/4.4.3.4000 Chrome/30.0.1599.101 Safari/537.36' |
| |
| |
| agent_list=[agent_one,agent_two,agent_three, |
| agent_four,agent_five,agent_seven, |
| agent_eight,agent_night,agent_ten, |
| agent_eleven,agent_twelve,agent_thirteen, |
| agent_fourteen,agent_eighteen,agent_nineteen,agent_twenty |
| ] |
| |
| Agent=random.choice(agent_list) |
| |
| |
| header={'User-Agent':Agent} |
| |
| |
| url=r'http://www.baidu.com/' |
| |
| |
| http_hander=request.HTTPHandler() |
| |
| |
| opener=request.build_opener(http_hander) |
| |
| |
| req=request.Request(url,headers=header) |
| |
| |
| reponse=opener(req).read().decode() |
| |
| |
| |
| |
| pat=r'<title>(.*?)</title>' |
| data=re.findall(pat,reponse) |
| |
| |
| print(data[0])COPY |