Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/84.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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
打开时出错。连接(x,“rb”):HTTP错误404,带有读取html函数_R_Url_Web Scraping_Xml2 - Fatal编程技术网

打开时出错。连接(x,“rb”):HTTP错误404,带有读取html函数

打开时出错。连接(x,“rb”):HTTP错误404,带有读取html函数,r,url,web-scraping,xml2,R,Url,Web Scraping,Xml2,在使用xml2包中的read_html函数时,我遇到了以下错误: Error in open.connection(x, "rb") : HTTP error 404. 以下是我试图读取的URL: xml2::read_html("https://www.act.is/media-centre/press-releases/actis-energy-platform-zuma-energía-reaches-financial-close-on-two-further-solar-farms-

在使用xml2包中的
read_html
函数时,我遇到了以下错误:

Error in open.connection(x, "rb") : HTTP error 404.
以下是我试图读取的URL:

xml2::read_html("https://www.act.is/media-centre/press-releases/actis-energy-platform-zuma-energía-reaches-financial-close-on-two-further-solar-farms-in-mexico/")
相比之下,读取此URL时没有生成错误

xml2::read_html("https://www.act.is/media-centre/press-releases/actis-wins-cio-magazine-s-real-asset-award/")
第一个URL包含一个带有重音符号“energía”的单词,第二个URL不包含。
可以读取包含带重音符号的单词的URL吗?

URL中有特殊字符,您必须转义它们。在Python中,有用于此的HTTP库,在R中可以找到

Python表达式:

base_url = "https://www.act.is/media-centre/press-releases/"
encoded_url = requests.utils.quote("actis-energy-platform-zuma-energía-reaches-financial-close-on-two-further-solar-farms-in-mexico/")
response = requests.get(base_url + encoded_url)
编码URL:


如果答案有帮助,你可以