gpt4 book ai didi

r - 网页抓取(在 R 中?)

转载 作者:行者123 更新时间:2023-12-02 06:08:50 26 4
gpt4 key购买 nike

我想获取this中间栏的公司名称页面(以蓝色粗体书写),以及登记投诉人的位置指示符(例如“印度,德里”,以绿色书写)。基本上,我想要一个包含两列的表(或数据框),一列用于公司,另一列用于位置。有任何想法吗?

最佳答案

您可以使用 R 中的 XML 包轻松完成此操作。这是代码

url = "http://www.consumercomplaints.in/bysubcategory/mobile-service-providers/page/1.html"
doc = htmlTreeParse(url, useInternalNodes = T)

profiles = xpathSApply(doc, "//a[contains(@href, 'profile')]", xmlValue)
profiles = profiles[!(1:length(profiles) %% 2)]

states = xpathSApply(doc, "//a[contains(@href, 'bystate')]", xmlValue)

关于r - 网页抓取(在 R 中?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5830705/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com