R - 在网站上发送搜索请求

R - Sending search request on a website

我有一个小问题,涉及在网站上发布搜索请求并使用 R 包 rvest 和 httr 显示结果...我只想 运行 一次搜索名称 "Acer campestre",并只勾选方框 "Match whole words only"。这是我的代码:

library(httr)
library(rvest)
col = POST(url="http://www.catalogueoflife.org/col",
           encode="form",
           body=list(text="Acer campestre",
                     fossil="0",
                     match="1",
                     submit="Search"))
col_html = read_html(col)
col_table = html_table(col_html,fill=T)

我想我离答案不太远,但似乎我总是无法使用这种使用 html 代码的命令...希望有人能帮助我,提前致谢!

好的,

最后还是自己解决了,问题出在三个方面:

-不是"fill=T"而是"fill=F"

-为 post 请求调用的输入错误:不是 "text",而是 "key",不是 "submit",而是 "search"...

-最后但并非最不重要:默认 URL“http://www.catalogueoflife.org/col" was not the one to use. "http://www.catalogueoflife.org/col/search/all”是用于实际 post 请求或与网页交互的正确选项...这是代码:

library(rvest)
library(httr)
col = POST(url="http://www.catalogueoflife.org/col/search/all",
           encode="form",
           body=list(key="Acer campestre",
                     fossil="0",
                     match="1",
                     search="Search"))
col_html = read_html(col)
col_table = html_table(col_html,fill=F)

然后,给网页的内容一个漂亮的table !

希望对大家有所帮助:)