這是網站請求的是Request Header 和攜帶的參數
import urllib
import urllib2
def GetFormDate( pageNum , catId ):
retValue = {}
retValue["module"] = "product"
retValue["from"] = "category"
retValue["page"] = "%d" % pageNum
paramJson = {"mobile" : False , "catalog" : "coo8Store" , "siteId" : "coo8Site" , "shopId" : "" , "regionId" : "31010100" , "pageName" : "list" , "et" : "" , "XSearch" : False , "startDate" : 0 , "endDate" : 0 , "pageSize" : 48 , "state" : 4 , "weight" : 0 , "more" : 0 , "sale" : 0 , "instock" : 1 , "filterReqFacets" : None , "rewriteTag" : False , "userId" : "" , "priceTag" : 0}
paramJson["catId"] = catId
retValue["paramJson"] = paramJson
return retValue
body=urllib.urlencode(GetFormDate(2,"cat15965738"))
request = urllib2.Request("http://www.gome.com.cn/p/asynSearch" )
request.add_header("Referer", "http://www.gome.com.cn/category/cat15965738.html")
request.add_header('Content-Type','application/json')
request.add_header('X-Requested-With','XMLHttpRequest')
request.add_header('HOST','www.gome.com.cn')
request.add_header('Accept-Language','zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3')
request.add_header('Accept','application/json, text/javascript, /; q=0.01')
f = urllib2.urlopen(request , json.dumps(GetFormDate(2,"cat15965738")))
content = f.read()
print content
這樣寫的話,獲得的Content 一直是空,有哪位大神知道為什麼嗎,求解啊
兩個格式是否完全一致?自己仔細對比一下