UltraDebug

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: A C D R G Y M Z X S P
公益项目,接受捐赠
查看: 1849|回复: 0
收起左侧

[Web逆向] 淘宝关键词搜索爬取与解析

[复制链接]
kugoumusic

主题

0

回帖

UD

新手上路

UID
18
积分
18
注册时间
2022-2-9
最后登录
1970-1-1
2023-2-7 20:51:36 | 显示全部楼层 |阅读模式

淘宝关键词搜索及X5滑块

  • 环境
  • win10、mac
  • Python3.9

根据关键词获取品牌列表

淘宝关键词搜索爬取与解析 - kugoumusic_UltraDebug

先根据搜索关键词获取到所有的品牌id:也就是ppath参数,目的是这样可以筛选更精准的数据,因为默认只显示100页数据

    def get_brand(self):
        """
        根据关键词获取品牌列表
        """
        headers = {
            "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
            "Accept-Language": "zh-CN,zh;q=0.9",
            "Cache-Control": "no-cache",
            "Connection": "keep-alive",
            "Pragma": "no-cache",
            "Referer": "https://s.taobao.com/search?q=^%^E7^%^AC^%^94^%^E8^%^AE^%^B0^%^E6^%^9C^%^AC^%^E7^%^94^%^B5^%^E8^%^84^%^91&imgfile=&js=1&stats_click=search_radio_tmall^%^3A1&initiative_id=staobaoz_20230127&tab=mall&ie=utf8&bcoffset=0&p4ppushleft=^%^2C44&style=grid&s=0",
            "Sec-Fetch-Dest": "document",
            "Sec-Fetch-Mode": "navigate",
            "Sec-Fetch-Site": "same-origin",
            "Sec-Fetch-User": "?1",
            "Upgrade-Insecure-Requests": "1",
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36",
            "sec-ch-ua": "^\\^Not_A",
            "sec-ch-ua-mobile": "?0",
            "sec-ch-ua-platform": "^\\^Windows^^",
        }
        cookies = {
            "cookie2": "1c1f03c4df47307258a30c65ce1db555",
        }
        url = "https://s.taobao.com/search"
        params = {
            "q": self.word,
            "imgfile": "",
            "js": "1",
            "stats_click": "search_radio_tmall^%^3A1",
            "initiative_id": "staobaoz_20230127",
            "tab": "mall",
            "ie": "utf8",
            "style": "grid"
        }
        # response = requests.get(url, headers=headers, params=params)
        response = self._parse_url(url=url, headers=headers, params=params)
        if not response:
            yield None
        # print(response.text)
        res = re.findall(r'g_page_config = (.*?)};', response.text, re.M | re.S)
        if not res:
            yield None
        datas = jsonpath.jsonpath(json.loads(res[0] + "}"), "$..sub")
        if not datas:
            yield None
        for data in datas[0]:
            yield data

根据关键词、品牌、销量搜索商品列表

淘宝关键词搜索爬取与解析 - kugoumusic_UltraDebug

具体的参数多抓几个包对比一下,很容易就分析出来了

    def get_products(self, ppath, page):
        """
        获取商品列表 根据销量排序
        ppath:品牌代码
        page:翻页
        """
        headers = {
            "Accept": "*/*",
            "Accept-Language": "zh-CN,zh;q=0.9",
            "Cache-Control": "no-cache",
         &n
还有更多的精彩内容,作者设置为付费后可见
UltraDebug免责声明
✅以上内容均来自网友转发或原创,如存在侵权请发送到站方邮件9003554@qq.com处理。
✅The above content is forwarded or original by netizens. If there is infringement, please send the email to the destination 9003554@qq.com handle.
回复 打印

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|站点地图|UltraDebug ( 滇ICP备2022002049号-2 滇公网安备 53032102000034号)

GMT+8, 2025-6-21 01:36 , Processed in 0.046619 second(s), 11 queries , Redis On.

Powered by Discuz X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表