侧边栏壁纸
博主头像
海绵

正向的根基决定逆向的上限

  • 累计撰写 32 篇文章
  • 累计创建 29 个标签
  • 累计收到 21 条评论

post请求传参(payload)

海绵
2022-02-24 / 0 评论 / 1 点赞 / 491 阅读 / 518 字
def scrape(url, headers, method, num=5, payload=None):
    if num == 0: return
    proxies = random_ip()
    try:
        if method == 'get':
            ret = requests.get(url, headers=headers, timeout=3, proxies=proxies, allow_redirects=False)
        else:
            ret = requests.post(url, headers=headers, json=payload, timeout=3, proxies=proxies, allow_redirects=False)
        if ret.status_code == requests.codes.ok:
            ret.encoding = 'utf-8'
            print(ret.text)
            return ret.text
        else:
            print(f'状态码为{ret.status_code}')
            print(ret.text)
            assert False
    except Exception as e:
        print(f'出错了,还有{num}次', e)
        num -= 1
        return scrape(url, headers, num)
0

评论区