Web用R刮擦动态网页
我的目标是从此站点获取数据: https://www.insee.fr/fr/recherche?q= emploi-population+active+active+en +2018& amp;taille=20& amp; debut=0 ,尤其是尤其。
我知道获得功能不起作用,因为它是动态的,需要通过JavaScript进行处理(相同的是 Web刮擦动态网页python )。因此,我通过浏览器的检查器模式获取信息,并找到了带有URL的帖子查询。
这是一个可生殖的示例:
library(httr)
body <- list(q="Emploi-Population%20active%20en%202018",
start="0",
sortFields=data.frame(field="score",order="desc"),
filters=data.frame(NULL),
rows="50",
facetsQuery=data.frame(NULL))
TMP <- httr::POST(url = "http://www.insee.fr/fr/solr/consultation?q=Emploi-Population%20active%20en%202018",
body = body,
config = config(http_version=1.1),
encode = "json",verbose())
请注意,AI必须放置HTTP而不是HTTP,因为我什么也没得到(我什么也没得到(我的代理已正确配置,Rstudio可以连接到Internet)。
我得到的只是一个不错的500错误。对我想念什么的想法吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以更改
Q
参数并将其从URL中删除。我将使用HTTPS并删除您的配置行,以避免卷发提取错误。但是,下面适合返回100个结果,仍然有效。You can change the
q
param and remove it from your url. I would use https and remove your config line to avoid the curl fetch error. However, the below, adapted to return 100 results, still works.我发现将JSON作为字符串运行正常:
现在
输出
是一个巨大的列表,例如,在2022-05-31创建的文档标题: reprex package (v2.0.1)
I found that passing the json as a string worked fine:
Now
output
is a massive list, but here for example are the document titles:Created on 2022-05-31 by the reprex package (v2.0.1)