0

我正在尝试自动执行以下url的注册过程

import trio
import httpx
from sys import argv
from bs4 import BeautifulSoup


mainurl = 'https://www.g3telecom.com/signup'


headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0"
}

limiter = trio.CapacityLimiter(10)


async def get_soup(content):
    return BeautifulSoup(content, 'lxml').select_one('input[name="__RequestVerificationToken"]')['value']


async def worker(num, sender):
    async with limiter, sender, httpx.AsyncClient(timeout=10, headers=headers) as client:
        r = await client.get(mainurl)
        token = await get_soup(r.text)

        data = {
            "ProductID": "0",
            "PhilippineProductID": "",
            "AdvLeadSource": "",
            "LeadPage": "",
            "Csrrep_Create": "0",
            "ServiceType": "Long Distance",
            "FirstName": "Sam",
            "LastName": "Dam",
            "Email": "sam@dam.com",
            "ContactPhone": num,
            "Command": "Continue With Signup",
            "__RequestVerificationToken": token,
            "ContactPhoneMobile": "false",
            "Solicitation": "false"
        }
        r = await client.post(mainurl, data=data)
        print(r.status_code)


async def main():
    async with trio.open_nursery() as nurse, await trio.open_file(argv[1]) as f:
        sender, receiver = trio.open_memory_channel(0)
        nurse.start_soon(rec, receiver)

        async with sender:
            async for num in f:
                nurse.start_soon(worker, num.rstrip(), sender.clone())


async def rec(receiver):
    pass

if __name__ == "__main__":
    trio.run(main)

它的响应应该与302您从浏览器执行时相同,但看起来 POST 请求未正确发送。我注意到,如果我复制了浏览器 cookie 并包含在标头中,那么请求会成功进行,那么我该如何自动化呢?

测试编号:2102102299

4

0 回答 0