本文所有教程及源码、软件仅为技术研究。不涉及计算机信息系统功能的删除、修改、增加、干扰,更不会影响计算机信息系统的正常运行。不得将代码用于非法用途,如侵立删!
def get_brand(self): """ 根据关键词获取品牌列表 """ headers = { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,**", "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&style=grid&stats_click=search_radio_tmall^%^3A1&initiative_id=staobaoz_20230127&tab=mall&ie=utf8&bcoffset=0&p4ppushleft=^%^2C44&cps=yes&ppath=20000^%^3A11119&sort=sale-desc&s=44", "Sec-Fetch-Dest": "script", "Sec-Fetch-Mode": "no-cors", "Sec-Fetch-Site": "same-origin", "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^^", } url = "https://s.taobao.com/search" params = { "data-key": "s", "data-value": page, "ajax": "true", "_ksTS": "1674837683322_2012", "callback": "jsonp2013", "q": self.word, "imgfile": "", "js": "1", "style": "grid", "stats_click": "search_radio_tmall^%^3A1", "initiative_id": "staobaoz_20230127", "tab": "mall", "ie": "utf8", "bcoffset": "0", "p4ppushleft": "^%^2C44", "cps": "yes", "ppath": ppath, "sort": "sale-desc", "s": '' } # 第一页的时候请求参数不一样 if page == 1: params['data-value'] = '0,1' params['data-key'] = 's,ps' params['s'] = (int(page) - 1) * 44 else: params['data-value'] = int(page) * 44 params['s'] = (int(page)-1) * 44 response = requests.get(url, headers=headers, params=params) return response.text
本文仅供学习交流使用,如侵立删!