import requests
import re
def getHTMLText(url):
kv = {'cookie': '', 'user-agent': 'Mozilla/5,0'}
try:
r = requests.get(url, headers=kv, timeout=30)
r.encoding = r.apparent_encoding
return r.text
except:
return ""
def parsePage(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 = "\t{:^4}{:^8}\t{:^16}"
count = 0
print(tplt.format("序号", '价格', '名称',))
for i in ilt:
count = count + 1
print(tplt.format(count, i[0], i[1]))
def main():
goods = '恒温加热器'
depth = 56
infoilt = []
start_url = 'https://s.taobao.com/search?q=' + goods
for i in range(depth):
try:
url = start_url + '&s=' + str(44 * i)
html = getHTMLText(url)
parsePage(infoilt, html)
except:
continue
printGoodsList(infoilt)
main()
他导出的结果是这个样子,我就是想问一下有没有大佬帮个忙帮我导出商品的url,谢谢
还有他的38行的depth是什么意思呀,求大佬解答
谢谢
你这是想爬淘宝的商品链接信息?用selenium比较方便