如何正确地向Pypetteer中的网站发送POST请求

2024-05-29 03:28:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试用pyppeteer编写一个机器人。 我试图用我的代码向带有特定postData的网站发送POST请求

        Add_url = f"https://www.website.com/shop/{productID}/add.json"
        await page.setExtraHTTPHeaders(headers=headers)
        await page.setRequestInterception(True)
        page.o
        atc_post = await Request.continue_(self,overrides={'url':Add_url, 'method':'POST','postData':data})
        print(atc_post.json())

这是终端的电流输出:

文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/pyppeteer/network\u manager.py”,第447行,在continue\u

如果不是自己.\u异常:

AttributeError:“Bot”对象没有属性“\u AllowEnteption”

如果有人能帮忙,我将不胜感激


Tags: 代码addjsonurlpage机器人awaitpost
1条回答
网友
1楼 · 发布于 2024-05-29 03:28:15

Request.continue_仅在拦截后有效,例如:

async def intercept (req):
    print (req.headers)
    await req.continue_ ()
    pass

async def main():
    browser = await launch()
    page = await browser.newPage()
    await page.setRequestInterception(True)
    page.on ('request', lambda req: asyncio.ensure_future (intercept (req)))
    await page.goto('https://www.exemple.com') 
    await browser.close()
    return html

html=asyncio.get_event_loop().run_until_complete(main())

相关问题 更多 >

    热门问题