【发布时间】:2019-12-13 19:04:22
【问题描述】:
我想从网站获取数据,但响应只显示错误。
我尝试将 url 更改为导致 405 错误的 http,并尝试将 data=json.dumps(data) 更改为仅 data = data,但它们都不起作用。
import requests
import json
from bs4 import BeautifulSoup
request_url = 'https://www.kinds.or.kr/news/newsResult.do'
data = {"jsonSearchParam": {"indexName": "news", "searchKey": "sky", "searchKeys": [{}], "byLine": "", "searchFilterType": "1", "searchScopeType": "1", "mainTodayPersonYn": "", "startDate": "2019-05-06", "endDate": "2019-08-06", "newsIds": [
], "categoryCodes": [], "incidentCodes": [], "networkNodeType": "", "topicOrigin": ""}, "index-name": "news", "N": "", "search-keyword": "sky", "search-index-type": "news", "dict-type": "texanomy", "dict-concat": "OR"}
response = requests.post(request_url, data=json.dumps(data))
html = response.text
soup = BeautifulSoup(html, 'html.parser')
flist = soup.find_all('span')
print(response)
我希望得到适当的回应。
【问题讨论】:
-
404 HTTP 状态码表示服务器找不到请求的资源。你确定你发送的是正确的请求吗?尝试首先在Postman 中发出此 POST 请求,以更详细地检查情况。
标签: python json post beautifulsoup request