我的任务是从网站页面https://www.dobovo.com/获得一份公寓预订日历。当页面加载时,站点本身接收来自post请求的json格式的数据。当我发送一个类似的请求时,我得到如下错误{'success': False, 'error': 'Method GET is not allowed'}
,尽管我是用post方法发布请求的。在
有趣的是,几天前我可以用同样的方法得到数据。
有趣的是,我可以从终端获得这个json:curl -d "id=89740&date=2017-07-01" https://www.dobovo.com/dobovo/apt/ajax.php?action=getCalendar&lang=en
或{
我的Python代码:
from requests import post
def get_calendar(url):
ajax = 'http://www.dobovo.com/dobovo/apt/ajax.php?action=getCalendar&lang=en'
first_day_in_month = '2017-07-01'
id_ = url[-10:-5]
form_data = {
'id': id_,
'date': first_day_in_month
}
response = post(url=ajax, data=form_data)
return response.json()
这里的url是指向带有日历的页面的链接,如https://www.dobovo.com/zaporozhye-apartments/orchid-82731.html
请告诉我,我做错什么了?在
根据sigmavirus24's answer,只有在重定向发生时,POST请求才会更改为获取。似乎dobovo.com仅在https中工作,因此在ajax变量中将“http”更改为“https”,您将没事。
相关问题 更多 >
编程相关推荐