Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/404.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
Javascript 使用rvest从HTML表中抓取Web_Javascript_Html_R_Web Scraping - Fatal编程技术网

Javascript 使用rvest从HTML表中抓取Web

Javascript 使用rvest从HTML表中抓取Web,javascript,html,r,web-scraping,Javascript,Html,R,Web Scraping,我不熟悉网页抓取,正在尝试抓取下表: <table class="dp-firmantes table table-condensed table->striped"> <thead> <tr> <th>FIRMANTE</th&g

我不熟悉网页抓取,正在尝试抓取下表:

                    <table class="dp-firmantes table table-condensed table->striped">
                        <thead>
                            <tr>
                                <th>FIRMANTE</th>
                                <th>DISTRITO</th>
                                <th>BLOQUE</th>
                            </tr>
                        </thead>
                        <tbody>

                            <tr>
                                <td>ROMERO, JUAN CARLOS</td>
                                <td>SALTA</td>
                                <td>JUSTICIALISTA 8 DE OCTUBRE</td>
                            </tr>
                            <tr>
                                <td>FIORE VIÑUALES, MARIA CRISTINA DEL >VALLE</td>
                            <td>SALTA</td>
                                <td>PARES</td>
                            </tr>
                            </tbody>
                    </table>

坚定的
分发
斑点
罗梅罗,胡安·卡洛斯
萨尔塔
奥克图布雷8号法官
玛丽亚·克里斯蒂娜·德尔瓦勒·菲奥雷·维尼乌莱斯
萨尔塔
削减
我正在使用rvest软件包,代码如下:

link <- read_html("https://www.hcdn.gob.ar/proyectos/resultados-buscador.html?")
table <- html_nodes(link, 'table.dp-firmantes table table-condensed table-striped')

link您可以尝试使用以下代码来解析包含这些票据的“Listado de Autores”表。例如,第820/18号支出账单(link=)就有这个表,但我浏览了前500张账单,没有找到其他有这样数据的账单

library(tidyverse)
library(rvest)

html_object <- read_html('http://www.senado.gov.ar/parlamentario/comisiones/verExp/820.18/S/PL')

html_object %>% 
html_node(xpath = "//div[@id = 'Autores']/table") %>% # This is the xpath adress that worked for me. The CSS locator ypu provide did not work.
html_table() %>% as_data_frame() %>% ## Get the html table and store it in a tibble
mutate(X1 = gsub("\\n|\\t|  ", "", X1)) ##Remove the extra line brakes (\\n), tabs (\\t), and spaces ("  ") present in the html table.
库(tidyverse)
图书馆(rvest)
html_对象%
html_node(xpath=“//div[@id='Autores']/table”)%%>%#这是对我有效的xpath地址。CSS定位器ypu提供的不起作用。
html_table()%>%作为_data_frame()%>%##获取html表并将其存储在TIBLE中
mutate(X1=gsub(“\\n | \\t |,”,X1))###删除html表中的额外行制表符(\\n)、制表符(\\t)和空格(“”)。
结果:

# A tibble: 2 x 2
  X1
  <chr>
1 Romero, Juan Carlos
2 Fiore Viñuales, María Cristina Del Valle
#一个tible:2x2
X1
1罗梅罗,胡安·卡洛斯
2菲奥雷·维努阿莱斯,玛丽亚·克里斯蒂娜·德尔·瓦勒
编辑:通过read_html捕获Rśhtml的屏幕截图https://www.hcdn.gob.ar/proyectos/resultados-buscador.html?pagina=2")


该urlKaitlin上不存在节点(表),您提供的url似乎不会将我们带到包含您描述的表的页面。对于isntance,在html表格代码中,似乎列出了支持法案的国会议员的姓名。但是你提供的url只列出了法案,而没有列出国会议员。你是指下面这样的表格吗?似乎只有少数法案有这些额外的链接,指向有关其立法程序的更多信息。因此,当我手动浏览搜索结果时,链接似乎没有显示我看到的表。我不确定这是否意味着表的编码有问题?基本上,如果我使用此链接:并搜索所有法案,搜索结果页面将显示表格,其中包含签署法案的议员及其选区等的信息。这将起作用,但不幸的是,我也需要众议院法案的这些信息。我们很乐意提供帮助,但是请告诉我们可以在哪里找到它们的URL。这是我一直使用的链接:我刚刚搜索了所有的账单,这就是我引用上面html表的页面。谢谢你的帮助!我需要知道你在表格中输入了什么。例如,我在“Tipo de Proyecto”中输入了“Tipo de Proyecto”TODO,然后没有调整任何其他搜索功能。我已经找到了一种方法,可以使用rvest包中的html_session()和jump_to()函数自动导航搜索结果。但如果可能的话,我希望能够收集搜索结果页面表格中的数据,其中提供签署该法案的代表的姓名、所在地区和政党。