import requests

import re

def getHTMLText(url):

try: r=requests.get(url,timeout=30) r.raise_for_status() r.encoding=r.apparent_encoding return r.text except: return""def parserPage(ilt,html): try: plt=re.findall(r"view_price":"[d.]*",html) tlt=re.findall(r"raw_title"".*?",html) for i in range(len(plt)): price=eval(plt[i].split(:)[1]) title=eval(tlt[i].split(:)[1]) ilt.append([price,title]) except: print("")def printGoodsList(ilt): tplt="{:4} {:8} {:16}" print(tplt.format("序號","價格","商品名稱")) count=0 for g in ilt: count=count+1 print(tplt.format(count,g[0],g[1])) print("")def main(): goods=書包 depth=2 start_url=http://s.taobao.com/search?q=+ goods infoList=[] for i in range(depth): try: url=start_erl+s=+str(44*i) html=getHTMLText(url) parserPage(infoList,html) excep


我沒運行程序,你可以把得到的網頁內容列印出來看一下,基本通過xhr延遲載入的,通過requests都得不到完整的數據


感覺你對淘寶有點不大尊敬啊小夥子哈哈哈哈

淘寶反爬做的特別好 練手不要用淘寶


那麼多try except 能報錯才怪


複製黏貼代碼的時候,先搞清楚每行代碼是幹啥的。


看看是不是反爬蟲導致的


推薦閱讀:
相关文章