【发布时间】:2018-04-05 05:05:04
【问题描述】:
我试图从网站获取 json 文件。我尝试了 BeautifulSoup 库,但它是空的。
在 DevTools 中不为空并且有一个示例 Jquery 代码:
$('#domtableweek').dataTable({
"processing": true,
"serverSide": true,
"bSort": false,
"bLengthChange": false,
"pageLength": 10,
ajax: {
url: '/data/mal-domains-data',
type: 'POST',
data: {'csrfmiddlewaretoken': 'yafh4aGjo0S6SeTci6qv2PzlcEuTW7E8', 'time':'7-Day'}
},
"dataSource": ''
});
所以我尝试了这段代码
import requests
csrf = 'some_csrf_token'
cookie = 'some_cookie_id'
data = dict({'csrfmiddlewaretoken': 'yafh4aGjo0S6SeTci6qv2PzlcEuTW7E8', 'time':'7-Day'})
url = 'https://minotr.net/data/mal-domains'
headers = {'Cookie':cookie}
r = requests.post(url, data=data, headers=headers)
print r.text
结果是:
<p>You are seeing this message because this HTTPS site requires a 'Referer header' to be sent by your Web browser, but none was sent. This header is required for security reasons, to ensure that your browser is not being hijacked by third parties.</p>
<p>If you have configured your browser to disable 'Referer' headers, please re-enable them, at least for this site, or for HTTPS connections, or for 'same-origin' requests.</p>
`
你能帮帮我吗?
【问题讨论】:
标签: jquery json python-2.7 python-requests