欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

获取京东商品信息报错error pdos_captcha

程序员文章站 2022-05-18 18:09:35
获取京东商品信息报错error pdos_captcha2020.7.20python 请求商品信息出现 {“error”:“pdos_captcha”}。添加header后解决问题:# 参数货物id 返回值价格def get_book_price(commodityID): Cookie = '' headers = { 'User-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537....

获取京东商品信息报错error pdos_captcha


2020.7.20
python 请求商品信息出现 {“error”:“pdos_captcha”}。
添加header后解决问题:

# 参数货物id   返回值价格
def get_book_price(commodityID):
    Cookie = ''

    headers = {
        'User-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36',
        'Cookie': Cookie,
        'Connection': 'keep-alive',
        'Accept': '*/*',
        'Accept-Encoding': 'gzip, deflate, sdch',
        'Accept-Language': 'zh-CN,zh;q=0.8',
        'Host': 'p.3.cn',
        'Referer': 'https://book.jd.com/booktop/0-0-0.html?category=1713-0-0-0-10001-1'
    }

    url = "https://p.3.cn/prices/mgets"

    payload = {'skuIds': commodityID}

    response = requests.get(url, params=payload, headers=headers)

    # print(response.status_code)
    # print(str(response.content))
    reg = r'(?<=op":").+(?=",)'
    price = re.search(reg,str(response.content), flags=0).group()
    return price

本文地址:https://blog.csdn.net/qq_42599719/article/details/107461538