Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何修复<;答复[404]>;发送post请求时出错_Python_Json_Post_Beautifulsoup_Request - Fatal编程技术网

Python 如何修复<;答复[404]>;发送post请求时出错

Python 如何修复<;答复[404]>;发送post请求时出错,python,json,post,beautifulsoup,request,Python,Json,Post,Beautifulsoup,Request,我想从站点获取数据,但响应只显示错误 我尝试将url改为http,这导致了405错误,并尝试将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": "ne

我想从站点获取数据,但响应只显示错误

我尝试将url改为http,这导致了405错误,并尝试将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)

我希望得到正确的回复。

您的url似乎不正确。查看Firefox开发工具,正确的搜索URL是
https://www.kinds.or.kr/v2/news/search.do“
。参数“jsonSearchParam”需要是一个json字符串,因此我们在其上使用
json.dumps()

import json
import requests
from bs4 import BeautifulSoup

# request_url = 'https://www.kinds.or.kr/news/newsResult.do'
request_url = 'https://www.kinds.or.kr/v2/news/search.do'   # <-- correct URL

d = {"indexName": "news", "searchKey": "sky", "searchKeys": [{}], "byLine": "", "searchFilterType": "1", "searchScopeType": "1", "mainTodayPersonYn": "", "startDate": "2019-05-06", "endDate": "2019-08-06", "newsIds": [], "categoryCodes": [], "incidentCodes": [], "networkNodeType": "", "topicOrigin": ""}
data = {"jsonSearchParam": json.dumps(d), "index-name": "news", "N": "", "search-keyword": "sky", "search-index-type": "news", "dict-type": "texanomy", "dict-concat": "+OR+"}

response = requests.post(request_url, data=data)
print(response)

soup = BeautifulSoup(response.text, 'lxml')
flist = soup.find_all('span')
print(flist)
导入json
导入请求
从bs4导入BeautifulSoup
#请求https://www.kinds.or.kr/news/newsResult.do'

请求https://www.kinds.or.kr/v2/news/search.do“#您的url似乎不正确。查看Firefox开发工具,正确的搜索URL是
https://www.kinds.or.kr/v2/news/search.do“
。参数“jsonSearchParam”需要是一个json字符串,因此我们在其上使用
json.dumps()

import json
import requests
from bs4 import BeautifulSoup

# request_url = 'https://www.kinds.or.kr/news/newsResult.do'
request_url = 'https://www.kinds.or.kr/v2/news/search.do'   # <-- correct URL

d = {"indexName": "news", "searchKey": "sky", "searchKeys": [{}], "byLine": "", "searchFilterType": "1", "searchScopeType": "1", "mainTodayPersonYn": "", "startDate": "2019-05-06", "endDate": "2019-08-06", "newsIds": [], "categoryCodes": [], "incidentCodes": [], "networkNodeType": "", "topicOrigin": ""}
data = {"jsonSearchParam": json.dumps(d), "index-name": "news", "N": "", "search-keyword": "sky", "search-index-type": "news", "dict-type": "texanomy", "dict-concat": "+OR+"}

response = requests.post(request_url, data=data)
print(response)

soup = BeautifulSoup(response.text, 'lxml')
flist = soup.find_all('span')
print(flist)
导入json
导入请求
从bs4导入BeautifulSoup
#请求https://www.kinds.or.kr/news/newsResult.do'

请求https://www.kinds.or.kr/v2/news/search.do“#404 HTTP状态代码表示服务器找不到请求的资源。您确定发送的请求正确吗?例如,尝试在first中发出此POST请求,以便更详细地检查情况。404 HTTP状态代码表示服务器找不到请求的资源。您确定发送的请求正确吗?试着提出这个POST请求,例如在first中,以更详细地检查情况。