当页面明显存在时获取404错误

2024-10-08 20:15:40 发布

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

所以我试图发出一个POST请求,但是我得到了一个404错误。当我在我的浏览器中跟踪链接时,它加载得很好,但是当我打印帖子回复的文本时,我得到的只是一个404页面

我尝试过使用标题,也尝试过使用“真实性令牌”

atc = requests.post('https://www.saintalfred.com/cart/add.js', data = cart)
print(atc.text)

atc.cookies.get_dict()

r = requests.post("https://www.saintalfred.com/checkout", data=params, timeout = 20, cookies = atc.cookies)

print(r.text)

html = r.text

r.cookies.get_dict()


checkouttoken = re.search('DF_CHECKOUT_TOKEN = "(.*?)"', html)
authenticityToken = re.search('authenticity_token" value="(.*?)"',html)

print(checkouttoken.group(1))
print(authenticityToken.group(1))
aaaaa = checkouttoken.group(1).split('{fun')

aaaaaa = ''.join(aaaaa)

print(aaaaaa)

urlthing = "https://www.saintalfred.com/2681785/checkouts/" + aaaaaa + '?_method=patch&authenticity_token=' + authenticityToken.group(1)
print(urlthing)

headers = {'User Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3'}

z = requests.post(urlthing, data=params, timeout = 20, headers = headers, cookies = r.cookies)

print(z.text)

预期:不是404

实际:404页


Tags: texthttpscomdatahtmlwwwgrouppost

热门问题