【问题标题】:Extracting Vcard information - R scraping提取 Vcard 信息 - R 抓取
【发布时间】:2018-10-23 10:06:56
【问题描述】:

有没有办法使用 R 从 vcard 中提取数据?我正在抓取一些网站,其中一个是 - https://www.cwlaw.com/attorneys

我需要从电子名片 - 电子邮件中收集信息。

【问题讨论】:

    标签: r web-scraping


    【解决方案1】:

    这是提取具有“mailto”的href并使用gsub将其删除。

     gsub("mailto:", "",grep("mailto:", read_html("https://www.cwlaw.com/attorneys")%>% html_nodes("a")%>% html_attr("href"), value= T))
    

    【讨论】:

      【解决方案2】:

      这是一种从电子名片中提取电子邮件地址的简单方法。

      这种方式使用 CURL 下载卡片,grep 查找带有字符串 EMAIL 的行,最后使用 stringr::str_split 捕获该行的相关部分。

      library(curl)
      library(stringr)
      
      con <- curl('https://www.cwlaw.com/vcard-82.vcf', open='')
      card <- readLines(con)
      str_split(grep('EMAIL', card, value=TRUE), 'CP1252:')[[1]][2]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-05-23
        • 2016-05-24
        • 1970-01-01
        • 2021-04-20
        • 1970-01-01
        • 2021-04-09
        • 1970-01-01
        相关资源
        最近更新 更多