问题
I want to read and parse the contents of the following page in R:
http://www.karriere.at/jobs/4442194
In particular I want to read the text which starts with "Ihr Aufgabenbereich:". This text is located in a separate inline frame (or iframe).
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)
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>
Can anyone help me out?
回答1:
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"
来源:https://stackoverflow.com/questions/33082778/how-can-i-read-and-parse-the-contents-of-an-iframe-in-r