简体   繁体   English

使用R进行网页抓取-看不到HTML

[英]Web scraping with R - no HTML visible

I am trying to use R scrape a website: 我正在尝试使用R抓取网站:

http://divulgacandcontas.tse.jus.br/divulga/#/candidato/2018/2022802018/GO/90000609234 http://divulgacandcontas.tse.jus.br/divulga/#/candidato/2018/2022802018/GO/90000609234

It has several fields with lots of information. 它具有许多信息的领域。 I am only interested in the url above the field "site do candidato". 我只对“ site do candidato”字段上方的网址感兴趣。 In this example, the url I want is: " http://vanderlansenador111.com.br " 在此示例中,我想要的网址是:“ http://vanderlansenador111.com.br

The problem is, there is no HTML (visible). 问题是,没有HTML(可见)。 So, I don't think using rvest is helpful (at least, I don't know how to use it). 因此,我认为使用rvest没有帮助(至少,我不知道如何使用它)。 Is there a way to scrape it without using selenium (I never used Rselenium and had some problems trying to run it). 有没有一种方法可以在不使用硒的情况下进行刮擦(我从未使用过Rselenium,并且在尝试运行它时遇到了一些问题)。

Points to any direction much appreciated. 指向任何赞赏的方向。

Don't waste your time with Selenium. 不要浪费您的硒时间。 Use the Developer Tools part of your browser to find the XHR request: http://divulgacandcontas.tse.jus.br/divulga/rest/v1/candidatura/buscar/2018/GO/2022802018/candidato/90000609234 使用浏览器的开发人员工具部分查找XHR请求: http : //divulgacandcontas.tse.jus.br/divulga/rest/v1/candidatura/buscar/2018/GO/2022802018/candidato/90000609234

and just use jsonlite::fromJSON() : 只需使用jsonlite::fromJSON()

str(jsonlite::fromJSON("http://divulgacandcontas.tse.jus.br/divulga/rest/v1/candidatura/buscar/2018/GO/2022802018/candidato/90000609234"))

The str() output is large & complete. str()输出大而完整。 You should be able to find what you need there. 您应该能够在那里找到所需的东西。

Selenium is a good choice for this, and alternative is you can use PhantomJS there is a good tutorial on the process over at datacamp (not as clean solution as Selenium) Selenium是一个不错的选择,另外一种选择是您可以使用PhantomJS在datacamp上有一个很好的关于过程的教程(不像Selenium那样干净)

https://www.datacamp.com/community/tutorials/scraping-javascript-generated-data-with-r https://www.datacamp.com/community/tutorials/scraping-javascript-generated-data-with-r

<div>在 HTML 中似乎是空的(r 中的网络抓取与 rvest)</div><div id="text_translate"><p> 我正在尝试使用 r 库 rvest 从博彩网站上抓取一些数据。<br> 为了获取这些值,我需要单击表格中的一些超链接。<br> 为此,我使用以下代码:</p><pre> odds_link &lt;- "https://www.oddsportal.com/soccer/germany/bundesliga/results/" odds_page &lt;- read_html(odds_link) node_table &lt;- html_node(xpath = '//*[@id="tournamentTable"]')</pre><p> 我用这个<a href="https://i.stack.imgur.com/fF5Hy.png" rel="nofollow noreferrer">xpath</a>和 node_table 返回这个</p><pre>{xml_nodeset (1)} [1] &lt;div id="tournamentTable"&gt;&lt;/div&gt;\n</pre><p> 返回的节点看起来是空的,因为 div 标签之间没有任何东西......它应该看起来像<a href="https://i.stack.imgur.com/HImMD.png" rel="nofollow noreferrer">那样</a>。<br> 在这一点上,我很失落。 我尝试了几件事,但没有成功。</p><pre> node_table %&gt;% html_node("table") node_table %&gt;% html_table() node_table %&gt;% html_structure()</pre><p> 这是返回的:</p><pre> &gt; node_table %&gt;% html_node("table") {xml_missing} &lt;NA&gt; &gt; node_table %&gt;% html_table() Fehler in html_table.xml_node(.): html_name(x) == "table" is not TRUE &gt; node_table %&gt;% html_structure() &lt;div#tournamentTable&gt;</pre><p> 我将不胜感激这方面的帮助! (下一步是访问表中的<a href="https://i.stack.imgur.com/R2zku.png" rel="nofollow noreferrer">这些</a>超链接。)<br> 我什至无法访问超链接...</p><pre> xpath_link = '//*[@id="tournamentTable"]/tbody/tr[4]/td[2]/a' odds_page %&gt;% html_node(xpath = xpath_link)</pre><pre> &gt; odds_page %&gt;% html_node(xpath = xpath_link) {xml_missing} &lt;NA&gt;</pre></div> - <div> in HTML seems to be empty (web scraping in r with rvest)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Web抓取:Chrome开发人员工具可看到html结构,但htmlTreeParse(R)无法看到 - Web scraping: html structure visible with chrome developer tool, but not with htmlTreeParse (R) R中的网页抓取html - web scraping html in R R中的Web抓取html表 - Web scraping html tables in R 使用 R - html 内容抓取网页 - Web scraping with R - html content 使用 rvest 和 R 抓取网页 html - Web scraping html with rvest and R R中的Web抓取和解析HTML - Web scraping and parsing HTML in R R 中的网页抓取:解析 HTML 表格的问题 - Web Scraping in R: Issues with parsing an HTML table R网页抓取-HTML中的隐藏文本 - R web-scraping - hidden text in HTML 关于 HTML 代码的混淆 Web 与 R 刮擦 - Confusion Regarding HTML Code For Web Scraping With R <div>在 HTML 中似乎是空的(r 中的网络抓取与 rvest)</div><div id="text_translate"><p> 我正在尝试使用 r 库 rvest 从博彩网站上抓取一些数据。<br> 为了获取这些值,我需要单击表格中的一些超链接。<br> 为此,我使用以下代码:</p><pre> odds_link &lt;- "https://www.oddsportal.com/soccer/germany/bundesliga/results/" odds_page &lt;- read_html(odds_link) node_table &lt;- html_node(xpath = '//*[@id="tournamentTable"]')</pre><p> 我用这个<a href="https://i.stack.imgur.com/fF5Hy.png" rel="nofollow noreferrer">xpath</a>和 node_table 返回这个</p><pre>{xml_nodeset (1)} [1] &lt;div id="tournamentTable"&gt;&lt;/div&gt;\n</pre><p> 返回的节点看起来是空的,因为 div 标签之间没有任何东西......它应该看起来像<a href="https://i.stack.imgur.com/HImMD.png" rel="nofollow noreferrer">那样</a>。<br> 在这一点上,我很失落。 我尝试了几件事,但没有成功。</p><pre> node_table %&gt;% html_node("table") node_table %&gt;% html_table() node_table %&gt;% html_structure()</pre><p> 这是返回的:</p><pre> &gt; node_table %&gt;% html_node("table") {xml_missing} &lt;NA&gt; &gt; node_table %&gt;% html_table() Fehler in html_table.xml_node(.): html_name(x) == "table" is not TRUE &gt; node_table %&gt;% html_structure() &lt;div#tournamentTable&gt;</pre><p> 我将不胜感激这方面的帮助! (下一步是访问表中的<a href="https://i.stack.imgur.com/R2zku.png" rel="nofollow noreferrer">这些</a>超链接。)<br> 我什至无法访问超链接...</p><pre> xpath_link = '//*[@id="tournamentTable"]/tbody/tr[4]/td[2]/a' odds_page %&gt;% html_node(xpath = xpath_link)</pre><pre> &gt; odds_page %&gt;% html_node(xpath = xpath_link) {xml_missing} &lt;NA&gt;</pre></div> - <div> in HTML seems to be empty (web scraping in r with rvest)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM