如何在R中读取和解析iframe的内容 [英] How can I read and parse the contents of an iframe in R

查看:88
本文介绍了如何在R中读取和解析iframe的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想阅读并解析R中下一页的内容:

I want to read and parse the contents of the following page in R:

http://www.karriere.at/jobs/4442194

我特别想阅读以"Ihr Aufgabenbereich:"开头的文本.该文本位于单独的嵌入式框架(或iframe)中.

In particular I want to read the text which starts with "Ihr Aufgabenbereich:". This text is located in a separate inline frame (or iframe).

我尝试使用R中的XML包,这是到目前为止我得到的:

I tried to work with the XML package in R, here is what I got so far:

url="http://www.karriere.at/jobs/4442194"
html <- getURL(url)
doc = htmlParse(html)

由于此网页的iframe代码包含的信息不多,我不知道从这里开始如何进行操作:

I don't know how to proceed from here, since the iframe tag of this webpage does not contain much information:

<iframe id="jobFrame" src="/html/4442194" frameborder="0"></iframe>

有人可以帮我吗?

推荐答案

iframe在 src 属性中包含您需要的所有信息:

The iframe contains all the information you need in the src attribute:

library(XML)
library(RCurl)
url="http://www.karriere.at/jobs/4442194"
html <- getURL(url)
doc = htmlParse(html)

url <- paste0("http://www.karriere.at", xmlGetAttr(doc[['/html/body/div[2]/iframe']], "src"))
doc = htmlParse(getURL(url))
xpathSApply(doc, "/html/body/div/div[2]/div[3]/ul/li", xmlValue, trim = TRUE)
# [1] "Neumontage von Klär - und Wasseraufbereitungsanlagenanlagen (teilweise Rohrleitungsbau- Kunststoff und Verkabelungsarbeiten)"
# [2] "Schaltanlagenbau (Verdrahtungsarbeit und Umbauarbeiten)"                                                                     
# [3] "Störungsbehebung an Steuerungen in Schaltanlagen Wasser- und Abwassertechnik"                                                
# [4] "Aufbauen von Umkehrosmoseanlagen (Meerwasserentsalzung)= Vormontage in unserer Werkstätte."                                  
# [5] "Servicearbeiten in der Abwassertechnik"                                                                                      
# [6] "Wartung von Anlagen"  

这篇关于如何在R中读取和解析iframe的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆