91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 4KB
    文件類型: .py
    金幣: 1
    下載: 0 次
    發布日期: 2021-05-13
  • 語言: Python
  • 標簽: 評論??爬取??Python??

資源簡介

自己寫的基于Python的淘寶評論爬取,并得到商品的圖片

資源截圖

代碼片段和文件信息

import?requests
import?re
import?io
import?sys
import?os
import?urllib.request
import?time

sys.stdout?=?io.TextIOWrapper(sys.stdout.bufferencoding=‘gb18030‘)
headers={“User-Agent“:“Mozilla/4.0(compatible;MSIE7.0;WindowsNT5.1;Trident/4.0;SE2.XmetaSr1.0;SE2.XmetaSr1.0;.NETCLR2.0.50727;SE2.XmetaSr1.0)“}
def?getHTMLText(url):
#得到商品的html
try:
r?=?requests.get(urlheaders=headerstimeout=30)
return?r.text
except:
return?““


def?parsePage(url):
#得到商品的list
infoList=[];
html=getHTMLText(url)
#print(html)
plt?=?re.findall(‘view_price“:“([\s\S]*?)“‘?html)
tlt?=?re.findall(‘raw_title“:“([\s\S]*?)“‘?html)
clt?=?re.findall(‘view_sales“:“([\s\S]*?)“‘html)
ilt?=?re.findall(‘nid“:“([\s\S]*?)“‘html)
photolt=re.findall(‘pic_url“:“([\s\S]*?)“‘html)
for?i?in?range(len(plt)):
price?=plt[i]
title?=?tlt[i]
customer?=?clt[i]
id?=?ilt[i]
photo=photolt[i]
infoList.append([pricetitlecustomeridphoto])
printGoodsList(infoList)

def?GetComment(goods_filenameurlitemId):
#得到某個商品評論放入商品的文件夾中
web_data=requests.get(urlheaders=headers);
goods_filename=goods_filename.replace(“?“““).replace(“、“““).replace(“\\“““).replace(“*“““).replace(“““““).replace(“”“““).replace(“<“““).replace(“>“““).replace(“|“““).replace(‘/‘‘‘)
itemId=itemId
#print(web_data.text)
spuId=re.search(‘spuId=([0-9]*)‘web_data.text).group(1);
sellerId=re.search(‘sellerId=([0-9]*)‘web_data.text).group(1)
#得到店家Id商品Id商鋪
time.sleep(3);
comment_url=str(“https://rate.tmall.com/list_detail_rate.htm?itemId=“+itemId+“&spuId=“+spuId+“&sellerId=“+sellerId+“&order=3¤tPage=1&append=0&content=1“)
web_data=requests.get(comment_urlheaders=headers);
f=open(‘E:\\淘寶爬取內容\\‘+goods_filename+“/pinglun.txt““w“)
#print(web_data.text)
try:
comment_num=re.search(‘lastPage“:([0-9]*)‘web_data.text).group(1)
#得到評論的頁數
if(int(comment_num)>3):
for?n?in?range(13):
comment_url=str(“https://rate.tmall.com/list_detail_rate.htm?itemId=“+itemId+“&spuId=“+spuId+“&sellerId=“+sellerId+“&order=3¤

評論

共有 條評論