RとXMLパッケージを使用して、XML htmlParse関数を使用して( "HTMLInternalDocument" "HTMLInternalDocument" "XMLInternalDocument" "XMLAbstractDocument")オブジェクトを解析しました。私が興味を持っているxmlオブジェクトの行には、以下の2つの値が含まれています。XMLノードから特定の値を解析します
class = gsc_1usr_nameの値( "Konrad Wrzecionkowski"を返す)のほかに、 "user ="(この場合は "QnVgFlYAAAAJ")の値を取得する必要があります。私はxpathSApplyでいくつかの構文バリエーションを試して、常にNULLを返します。確かに、それはXML、任意のアイデアになると私はかなり無知ですか?これをリストなどの別のオブジェクトクラスに強制する方法がありますか?そして、ベクトルでsplitを使用しますか?標準的な強制(例えば、as.list、as.character)は、このオブジェクトクラスでは動作しないようです。以下、XMLオブジェクトを返す
search.page <- "http://scholar.google.com/citations?hl=en&view_op=search_authors&mauthors=GVN Powell World Wildlife Fund"
x <- XML::htmlParse(search.page, encoding="UTF-8")
は、10のうちh3 class="gsc_1usr_name
ラインは、私は(すべての10のために)を取得したいことを、各エントリには、値が含まれ、単一のエントリのサブセットです。私は「GVNパウエル」を返す
</div>
</div>
<div class="gsc_1usr gs_scl">
<div class="gsc_1usr_photo"><a href="/citations?user=QnVgFlYAAAAJ&hl=en&oe=ASCII"><img src="/citations?view_op=view_photo&user=QnVgFlYAAAAJ&citpid=3" sizes="(max-width:599px) 75px,(max-width:1251px) 100px, 120px" srcset="/citations?view_op=view_photo&user=QnVgFlYAAAAJ&citpid=3 128w,/citations?view_op=medium_photo&user=QnVgFlYAAAAJ&citpid=3 256w" alt="Konrad Wrzecionkowski"></a></div>
<div class="gsc_1usr_text">
<h3 class="gsc_1usr_name"><a href="/citations?user=QnVgFlYAAAAJ&hl=en&oe=ASCII">Konrad Wrzecionkowski</a></h3>
<div class="gsc_1usr_aff">Zachodniopomorski Uniwersytet Technologiczny w Szczecinie, Błękitny Patrol <span class="gs_hlt">WWF </span>Polska</div>
<div class="gsc_1usr_eml">Verified email at <span class="gs_hlt">wwf</span>.pl</div>
<div class="gsc_1usr_emlb">@wwf.pl</div>
<div class="gsc_1usr_int">
<a class="gsc_co_int" href="/citations?view_op=search_authors&hl=en&oe=ASCII&mauthors=label:ichtiologia_ochrona_przyrody">ichtiologia/ochrona przyrody</a> </div>
</div>
</div>
だろうが、ユーザーからの値のような=。私はh3 [@ user = '']のバリエーションを試してみましたが、クラスのサブクエリは含まれていますが、他には何もできません。
XML::xpathSApply(x, "//h3[@class='gsc_1usr_name']", xmlValue)
私が使ってきたアプローチは、urlとreadLinesで行っています。次に、strsplitを使用して目的の値を取得します。
auth.names <- "Konrad Wrzecionkowski WWF"
search.page <- paste("http://scholar.google.com/citations?hl=en&view_op=search_authors&mauthors=", auth.names, sep="")
x <- readLines(url(search.page))
x <- strsplit(x[[1]], split="user=")[[1]][2]
x <- strsplit(x, split="&")[[1]][1]
ここでの問題は、Googleニュースは、ウェブをこすると、コードは定期的に失敗したいとしていないようだということで、エラー「を開くことができません接続、HTTPのステータスは「503サービスは利用できませんでした」。しかし、これはhtmlParseではそうではないようです。
がlibrary(rvest)
library(magrittr)
url <- "http://scholar.google.com/citations?hl=en&view_op=search_authors&mauthors=GVN Powell World Wildlife Fund"
xpath = "//*[@id=\"gsc_ccl\"]/div[1]/div[2]/h3/a/span"
gvn.powell <- url %>%
read_html %>%
html_nodes(xpath = xpath) %>%
html_text
gvn.powell
#[1] "GVN Powell"
あなたはおそらく '' タグからの 'のhref ='属性をつかむことができ – thelatemail
残念ながら、この構文は機能しませんでした。私は値を取得したいと思うXMLの10項目があります。私はxmlの詳細を提供するために投稿を修正しました。 –
Googleをスクレイピングすることは、ToSに違反しています。 – hrbrmstr