#!coding=utf-8
import requests
import re
import random
import time
import json
from requests.packages.urllib3.exceptions import InsecureRequestWarning
import pandas as pd
requests.packages.urllib3.disable_warnings(InsecureRequestWarning) ###禁止提醒SSL警告
class tm(object):####手机端
def __init__(self,path): ###保存数据路径
self.path=path
def goodsid(self,url): ###通过店铺URL获取店铺所有ID
shopname = re.search('https://(.*?).tmall', url).group(1)
searchurl = 'https://{}.m.tmall.com/shop/shop_auction_search.do?spm=a1z60.7754813.0.0.301755f0pZ1GjU&sort=defaul'.format(
shopname)
s=requests.session()
headers = {'Accept': '*/*',
'Accept-Language': 'zh-CN',
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_3 like Mac OS X) AppleWebKit/603.3.8 (KHTML, like Gecko) FxiOS/10.6b8836 Mobile/14G60 Safari/603.3.8',
'Referer':'https://{}.m.tmall.com/shop/shop_auction_search.htm?spm=a1z60.7754813.0.0.301755f0pZ1GjU&sort=default'.format(shopname)
}
s.headers.update(headers)
page1=s.get(url=searchurl,verify=False).text
print(page1)
js=json.loads(page1)
total_page=int(js['total_page'])
shop_id=js['shop_id']
shop_title = js['shop_title']
shop_id_list = []
shop_title_list = []
item_id=re.findall('"item_id":(.*?),"',page1)
title=re.findall('"title":"(.*?)","',page1)
sold=re.findall('"sold":"(.*?)","',page1)
totalSoldQuantity=re.findall('"totalSoldQuantity":(.*?),"',page1)
skuurl=re.findall('"url":"(.*?)","',page1)
price=re.findall('"price":"(.*?)","',page1)
item_id_l=len(item_id)
shop_id_list.append(shop_id)
shop_id_list.extend(shop_id_list*(int(item_id_l)-1))
shop_title_list.append(shop_title)
shop_title_list.extend(shop_title_list*(int(item_id_l)-1))
# print(js)
# print(len(shop_id_list))
# print(len(shop_title_list))
# print(len(item_id))
# print(len(title))
# print(len(sold))
# print(len(totalSoldQuantity))
# print(len(skuurl))
# print(len(price))
data = {'shop_id': shop_id_list,'shop_title': shop_title_list,'item_id': item_id, 'title': title, 'sold':sold, 'totalSoldQu
python爬虫爬取天猫店铺商品数据
最新推荐文章于 2023-09-09 20:32:32 发布