import requests
import re
import json
import csv
f=open('淘寶.csv','a+',encoding='utf-8',newline='')
csv_writer=csv.writer(f)
csv_writer.writerow(['商品類型','商品價格','已訂單數(shù)量','商鋪名稱','商品簡介','所在城市','商品地址'])
for page in range(0,100):
print(f'...正在爬取第{page}頁商品數(shù)據(jù).....')
#from pprint import pprint
# https://s.taobao.com/search?q=%E7%AC%94%E8%AE%B0%E6%9C%AC%E7%94%B5%E8%84%91&suggest=0_1
&commend=all&ssid=s5-e&search_type=item&sourceId=tb.index&spm=a21bo.jianhua.201856-taobao-item.2
&ie=utf8&initiative_id=tbindexz_20170306&_input_charset=utf-8&wq=%E7%AC%94%E8%AE%B0%E6%9C%AC
&suggest_query=%E7%AC%94%E8%AE%B0%E6%9C%AC&source=suggest&bcoffset=4&ntoffset=4&p4ppushleft=2%2C48&s=0
# https://s.taobao.com/search?q=%E7%AC%94%E8%AE%B0%E6%9C%AC%E7%94%B5%E8%84%91&suggest=0_1
&commend=all&ssid=s5-e&search_type=item&sourceId=tb.index&spm=a21bo.jianhua.201856-taobao-item.2
&ie=utf8&initiative_id=tbindexz_20170306&_input_charset=utf-8&wq=%E7%AC%94%E8%AE%B0%E6%9C%AC
&suggest_query=%E7%AC%94%E8%AE%B0%E6%9C%AC&source=suggest&bcoffset=1&ntoffset=1&p4ppushleft=2%2C48&s=44
# https://s.taobao.com/search?q=%E4%B8%9D%E8%A2%9C&commend=all&ssid=s5-e&search_type=item
&sourceId=tb.index&spm=a21bo.jianhua.201856-taobao-item.2&ie=utf8&initiative_id=tbindexz_20170306&bcoffset=-2
&ntoffset=-2&p4ppushleft=2%2C48&s=88
url=f'https://s.taobao.com/search?q=%E7%AC%94%E8%AE%B0%E6%9C%AC%E7%94%B5%E8%84%91&suggest=0_1
&commend=all&ssid=s5-e&search_type=item&sourceId=tb.index&spm=a21bo.jianhua.201856-taobao-item.2
&ie=utf8&initiative_id=tbindexz_20170306&_input_charset=utf-8&wq=%E7%AC%94%E8%AE%B0%E6%9C%AC
&suggest_query=%E7%AC%94%E8%AE%B0%E6%9C%AC&source=suggest&bcoffset=4&ntoffset=4&p4ppushleft=2%2C48&s={page*44}'
headers={
'cookie': 'miid=414303400140308027; cna=2oYnGj/yTg8CAXM+g1QJCbXu; thw=cn; _m_h5_tk=369c044014edb9abe215d37b7662e21e_1666848238671;
_m_h5_tk_enc=3fa0f00cd656bd645c47795cbbeff0f4; xlly_s=1; cookie2=1da1281e4c39b391784cee72fbc5a194; t=b08bbbefa536ed5787308fac84d12160;
_tb_token_=e78f7f58e176f; _samesite_flag_=true; sgcookie=E1005GCBc8FQMx59x9%2FQHXgxLXWpHNogVSaQhSIA0meqtBmp1aznsF6o9m0qamC1aClm
HPxpjKt96iGIyujBX0O%2Fh1DvtSrmtF%2BvJxzbxskJ7Uj1oyZ1QtP6k1Rr7jM8FxeZ; unb=761079275; uc3=lg2=W5iHLLyFOGW7aA%3D%3D&nk2=EFY19z3mm
Fyfsy3F&id2=VAcPTBBg4OHG&vt3=F8dCv4oZgZkCmRMPN5Y%3D; csg=10bc452b; lgc=shanyingnpxx; cancelledSubSites=empty; cookie17=VAcPTBBg4OHG;
dnk=shanyingnpxx; skt=4b8c6933cf7bd568; existShop=MTY2Njg0MDg0OA%3D%3D; uc4=nk4=0%40Eo9LPUTwF7EzjaVyz4B0D4CKR%2Bdad6Y%3D&id4=0
%40Vh5NAAt8Y%2FzFXt2s69bccNwQEFo%3D; tracknick=shanyingnpxx; _cc_=VFC%2FuZ9ajQ%3D%3D; _l_g_=Ug%3D%3D; sg=x5b; _nk_=shanyingnpxx; cookie1=
U%2BbLw1YcOjUIlBRU4o7otIl1UYUrVT7QTN%2BXOjOmXy8%3D; mt=ci=36_1; uc1=cookie21=VT5L2FSpczFp&cookie16=URm48syIJ1yk0MX2J7mAAEhTuw%3D
%3D&existShop=false&pas=0&cookie14=UoeyCG6kRimy5g%3D%3D&cookie15=U%2BGCWk%2F75gdr5Q%3D%3D; enc=%2BkHUYlHDC%2Fkwj3qlsXo
%2B9dCXSEYSAv4MI2ib%2FuSye6AF6%2BXvOp33V1Y%2F340G3pGhO9%2BaEb78RDdWYf5oyXf%2BIg%3D%3D; JSESSIONID=18D0865C13CEFD5B12D7F28ACCD0B067;
alitrackid=www.taobao.com; lastalitrackid=www.taobao.com; l=eBOSuxA4LYk1ExKyBOfZourza77TjIRAguPzaNbMiOCP_51p5hJ1W6y1Dw89CnGVh6nJR3JmWBbDBeYBqQAonxv92j-la_Mmn;
tfstk=cSIGB6t61N81fDZAO1t_VUg9MkzdZYo2ZiSCYJxdohzvGIjFiu3EzjhzKCV7_q1..; isg=BG5ut4hcgQCNkPVkMHlflfUMv8QwbzJp6thK7Zg30XEsew7VAP10eLd5N-eXoyqB',
'referer': 'https://www.taobao.com/',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.52'
}
respons=requests.get(url=url,headers=headers)
#print(respons.text)
htmldata=re.findall('g_page_config = (.*);',respons.text)[0]
json_data=json.loads(htmldata)
#rint(htmldata)
auctions=json_data["mods"]["itemlist"]["data"]["auctions"]
for auction in auctions:
raw_title=auction['raw_title']
view_price=auction['view_price']
view_sales=auction['view_sales']
shopName=auction['shopName']
title=auction['title'].replace('','').replace('u003c/span>','').replace('</span>電腦</span>','')
item_loc=auction['item_loc']
pic_url = auction['pic_url']
print(raw_title,view_price,view_sales,shopName,title,item_loc,pic_url)
csv_writer.writerow([raw_title,view_price,view_sales,shopName,title,item_loc,pic_url])
h='https:'
if h in pic_url:
img_url=pic_url
else:
img_url='https:'+pic_url
img=requests.get(url=img_url,headers=headers).content
with open('商品圖片\\'+shopName+'.jpg','wb') as phtofile:
phtofile.write(img)
好了,這篇文章的內(nèi)容發(fā)貨聯(lián)盟就和大家分享到這里,如果大家網(wǎng)絡(luò)推廣引流創(chuàng)業(yè)感興趣,可以添加微信:80709525 備注:發(fā)貨聯(lián)盟引流學(xué)習(xí); 我拉你進直播課程學(xué)習(xí)群,每周135晚上都是有實戰(zhàn)干貨的推廣引流技術(shù)課程免費分享!