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 能报错才怪


复制黏贴代码的时候,先搞清楚每行代码是干啥的。


看看是不是反爬虫导致的


推荐阅读:
相关文章