代码拉取完成,页面将自动刷新
同步操作将从 seven/pdd_crawler 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#-*-encoding:utf-8-*-
import requests
import execjs
from copyheaders import headers_raw_to_dict
import re
from urllib.parse import urlencode
session = requests.session()
def get_params():
headers = headers_raw_to_dict(
b'''
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Cache-Control: no-cache
Connection: keep-alive
Cookie: api_uid=rBUECV3bmWIWMBSFxJsVAg==; _nano_fp=Xpd8npP8XqdJnqEoXC_cAsjNmv0_PfL_IbsNUlws; ua=Mozilla%2F5.0%20(Windows%20NT%2010.0%3B%20WOW64)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F81.0.4044.113%20Safari%2F537.36; webp=1; PDDAccessToken=CYFFW7TDAAAATBSMO3T3JGDI2WY3RT5E7LLYECN5NOBZ4ZWFN5MA113ac8e; pdd_user_id=4318316460; pdd_user_uin=XAEIKBCPSFC6Q2Q45WP4NLFNII_GEXDA; JSESSIONID=1123038327A631257B25F7AC4D220B27
Host: m.yangkeduo.com
Pragma: no-cache
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36
'''
)
s = session.get( url = href, headers=headers)
if s.status_code == 200:
html = s .text
html = html.replace("\\", "")
list_id = re.search(r'list_id":"(.*?)"', html).group(1)
flip = re.search(r'flip":"(.*?)"', html).group(1)
return list_id, flip
def gen_signature( href ):
js = open("./get_anti.js", mode="r").read()
cxt = execjs.compile(js)
signature = cxt.call("get_anti_content", href)
return signature
def get_index( href ):
api_url = "http://m.yangkeduo.com/proxy/api/search?"
list_id , flip = get_params()
headers = headers_raw_to_dict(
b'''
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
AccessToken: *******************************
Connection: keep-alive
Cookie: api_uid=rBUECV3bmWIWMBSFxJsVAg==; _nano_fp=Xpd8npP8XqdJnqEoXC_cAsjNmv0_PfL_IbsNUlws; ua=Mozilla%2F5.0%20(Windows%20NT%2010.0%3B%20WOW64)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F81.0.4044.113%20Safari%2F537.36; webp=1; PDDAccessToken=CYFFW7TDAAAATBSMO3T3JGDI2WY3RT5E7LLYECN5NOBZ4ZWFN5MA113ac8e; pdd_user_id=4318316460; pdd_user_uin=XAEIKBCPSFC6Q2Q45WP4NLFNII_GEXDA; JSESSIONID=1123038327A631257B25F7AC4D220B27
Host: m.yangkeduo.com
Referer: http://m.yangkeduo.com/search_result.html?search_key=%E8%93%9D%E7%89%99%E8%80%B3%E6%9C%BA
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36
VerifyAuthToken:****************************
'''
)
data = {
"pdduid": "4318316460",
"item_ver": "lzqq",
"source": "search",
"search_met": "",
"list_id": list_id,
"sort": "default",
"filter": "",
"q": "蓝牙耳机",
"page": "2",
"size": "50",
"flip": flip,
"anti_content":gen_signature( href )
}
s = session.get( url = api_url + urlencode( data ),headers=headers )
if s.status_code == 200:
print( s.text )
href = "http://m.yangkeduo.com/search_result.html?search_key=%E8%93%9D%E7%89%99%E8%80%B3%E6%9C%BA"
get_index(href )
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。