【问题标题】:Extracting embedded url via website's HTML code R通过网站的 HTML 代码 R 提取嵌入的 url
【发布时间】:2017-01-05 12:31:30
【问题描述】:

所以我正在尝试将名为“North America Rotary Rig Count Pivot Table (Feb 2011 - Current)”的文件读入 R。但是,baker hughes 每周都会稍微更改 URL,所以我不能只是将 URL 复制并粘贴到在我的代码中。所以我的问题是,是否可以访问网站的 HTML 代码并在 R 中找到 URL 的位置?如果没有,除了手动复制和粘贴 URL 之外,访问 URL 的最佳方法是什么。

http://phx.corporate-ir.net/phoenix.zhtml?c=79687&p=irol-reportsother

【问题讨论】:

    标签: html r web


    【解决方案1】:

    这里是对我用来从网站中提取所有链接的代码的轻微修改。这将从 ahref 标记和显示的链接中提取所有链接。应该就足够了,尽管可以找到更有效的解决方案来查找单个链接。

    require(rvest)
    webpage = read_html(x='http://phx.corporate-ir.net/phoenix.zhtml?c=79687&p=irol-reportsother')
    filelink = 'North America Rotary Rig Count Pivot Table (Feb 2011 - Current)'
    
    urls = webpage %>%
            html_nodes('a') %>%
            html_attr('href')
    
    labels = webpage %>%
            html_nodes('a') %>%
            html_text() %>%
            trimws()
    
    links = data.frame(labels=labels, urls=urls)
    links[labels==filelink,]
                                                                 labels
    287 North America Rotary Rig Count Pivot Table (Feb 2011 - Current)
                                                                                                           urls
    287 http://phx.corporate-ir.net/External.File?item=UGFyZW50SUQ9NjU1OTg2fENoaWxkSUQ9MzYyMDEwfFR5cGU9MQ==&t=1
    

    【讨论】:

      猜你喜欢
      • 2019-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-13
      • 1970-01-01
      • 1970-01-01
      • 2017-05-20
      相关资源
      最近更新 更多