HTTP Referer是header的一部分,當瀏覽器向web服務器發送請求的時候,通常會帶上Referer,告訴服務器我是從哪一個頁面連接過來的,服務器籍此能夠得到一些信息用於處理。用於統計訪問量、防外鏈接等。php
import httplib,urllib2web
import randomjson
import time瀏覽器
i = 0服務器
while 1:dom
a = random.random()ide
b = str(a)ui
url = 'http://page.vote.qq.com/survey.php?PjtID=2439626&SubjID=2493278&OptID=184964&fmt=json&result=0&rdm='+b+'05827'url
httplib.HTTPConnection.debuglevel = 1debug
request = urllib2.Request(url)
request.add_header("Accept", "*/*")
request.add_header('Referer', "http://v.qq.com/zt2012/cstvf2012/tvactor.htm")
request.add_header("Accept-Language", "zh-cn")
request.add_header("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; MyIE9; BTRS123646; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)")
request.add_header("Accept-Encoding", "gzip, deflate")
request.add_header("Host", "page.vote.qq.com")
request.add_header("Connection", "Keep-Alive")
opener = urllib2.build_opener()
f = opener.open(request)
print f.url
i += 1
print i
time.sleep(60)