我已經使用XML
包中的R剛剛開始列表提取字符串和我有麻煩提取XML列表的字符串:如何使用正則表達式在XML從
> library("XML")
> library("stringr")
> url = "html-1.html"
> parsed_doc = htmlParse(file=url, useInternalNodes = TRUE)
> products <- getNodeSet(doc = parsed_doc, path = "//li[contains(.,Product ID')]")
> products
[[1]]
<li>
Product ID:
000002434482
</li>
[[2]]
<li>
Product ID:
000002183105
</li>
[[3]]
<li>
Product ID:
000002183105
</li>
我想創建一個包含每個ID的向量。我嘗試了一些正則表達式來提取12位數字的產品ID,但似乎無法使其正常工作。
> mrn <- str_extract(products , "[[:digit:]{12}")
> mrn <- str_extract(products , "[[:digit:]+
]")
> mrn <- str_extract(products , "[0-9]+
")
我想知道列表結構是否與它有關或可能是間距?
我也嘗試了> mrn <- str_extract(products , ".{16}")
然而,R返回指針值,如"<pointer: 0x6815"
- 我認爲這是接近,但我不知道這是什麼意思。