1

我无法使用以下参数发出发布请求:

网站: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

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

谢谢你的帮助

4

1 回答 1

2

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

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

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

data = serviceRequest.copy()
data.update(pageContext)
r = requests.post(Request_URL, data=data)
于 2012-11-23T11:55:37.640 回答