gpt4 book ai didi

Python POST 请求(网络抓取)

转载 作者:行者123 更新时间:2023-12-01 05:53:00 25 4
gpt4 key购买 nike

我无法使用这些参数发出发布请求:

网站:www.zoover.it

这是我的代码:

import requests

Request_URL="http://www.zoover.it/services/Testimonials/TestimonialQueryService.asmx/AccommodationTestimonialQuery"
serviceRequest:{"CurrentLanguage":"Language_NL","PartyFilter":"","CurrentPage":"0","PageSize":"10","SortOption":"date-of-visit"}
pageContext:{"EntityLevel":"accommodation","NewEntityLevel":"accommodation","EntityId":151433,"EntityName":"Residence Belmonte Vacanze****","SemanticName":"accommodation-testimonials","PhysicalUrl":"/accommodation/testimonials.aspx","CurrentSiteVariation":"it","CmsAccommodationTypeFilter":"","PageCode":"accommodation","PageSubcode":"testimonials","CmsEntity":{"Level":1,"Id":151433},"NewCmsEntity":{"Level":{"EntityLevel":"accommodation"},"Id":151433},"Path":"/accommodation/testimonials.aspx","PageSemantic":{"SemanticName":"accommodation-testimonials","PhysicalUrl":"/accommodation/testimonials.aspx","KnownFriendlyParams":["accommodationId"],"HasFriendlyUrl":true},"EntityType":"Appartamento","PageRequestUrl":"/italia/toscana/montaione/residence-belmonte-vacanze/appartamento"}

r = requests.post(Request_URL, params=serviceRequest)

print r.text

我有两个问题:

1) 在 R.TEXT 中,我总是收到“HTTP 错误 411。请求必须分块或具有内容长度。”
2)我不知道如何使用两个字典(serviceRequest和pageContext)进行POST

我的目标是通过更改字典的参数来进行网页抓取。

感谢您的帮助

最佳答案

改用data关键字,内容长度将自动设置:

r = requests.post(Request_URL, data=serviceRequest)

您必须将两个字典合并为一个:

data = serviceRequest.copy()
data.update(pageContext)
r = requests.post(Request_URL, data=data)

关于Python POST 请求(网络抓取),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13528593/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com