ウェブページには、ウェブページに1つのセルに複数の要素を持つ種類のテーブルがあります。私は次のコードでテーブルのコンテンツをクロールできますが、これらの要素をWebページアーキテクチャとしてバインドできませんでした。これらの要素を完全に組み合わせるためのいくつかの方法がありますか、または各要素を得るために他のアイデアを使用する必要がありますか?クロール中に複数の要素を持つテーブルのアーキテクチャを1つのセルに保持するR
library(XML)
dataissued <- "http://www.irgrid.ac.cn/handle/1471x/294320/browse?type=dateissued"
ec_parsed <- htmlTreeParse(dataissued, encoding = "UTF-8", useInternalNodes = TRUE)
# gether content in table and build the dataframe
# title and introduction link of IR resource
item_title <- xpathSApply(ec_parsed, '//td[@headers="t1"]//a', xmlValue)
item_hrefs <- xpathSApply(ec_parsed, '//td[@headers="t1"]//a/@href')
# author and introduction link of IR resource
auth_name <- xpathSApply(ec_parsed, '//td[@headers="t2"]//a', xmlValue)
auth_hrefs <- xpathSApply(ec_parsed, '//td[@headers="t2"]//@href')
# publish date of IR resource
pub_date <- xpathSApply(ec_parsed, '//td[@headers="t3"]', xmlValue)
# whole content link of IR resource
con_link <- xpathSApply(ec_parsed, '//td[@headers="t3"]//a[@href]', xmlValue)
item_table <- cbind(item_title, item_hrefs, auth_name, auth_hrefs, pub_date, con_link)
colnames(item_table) <- c("t1", "href1", "t2", "href2", "t3", "t4", "href4")
私は何度も試してみましたが、まだそれがあるべきように、1枚の紙が複数の著者を持っていること、およびすべての作者とそのリンクが一つの「行」に保存する必要がありますが、今は1本の著者と同じように、それらを整理することができません紙のタイトルは完全に再利用されています。それは結果を台無しにする。
私は 'con_link'を空にして、最後の行に6列を持つitem_tableに7つのcolnamesを割り当てようとするとエラーになります。コードを修正してください。 – xxfelixxx
それは残念です。私は、自分のコードは、それが鳴っているデータを組み合わせる上でいくつかのエラーがあると説明していましたが、私はそれを修正しようとしましたが、何も動作しませんでした。これに注目していただきありがとうございます。 –