R:LinkedIn使用rvest进行抓取

时间:2015-10-31 23:18:57

标签: r web-scraping rvest

使用rvest包,我正在尝试从我的LinkedIn profile抓取数据。

这些尝试:

library(rvest)
url = "https://www.linkedin.com/profile/view?id=AAIAAAFqgUsBB2262LNIUKpTcr0cF_ekoX9ZJh0&trk=nav_responsive_tab_profile"
li = read_html(url)
html_nodes(li, "#experience-316254584-view span.field-text")
html_nodes(li, xpath='//*[@id="experience-610617015-view"]/p/span/text()')

找不到任何节点:

#> {xml_nodeset (0)}
问:如何只返回文字?

#> "Quantitative hedge fund manager selection for $650m portfolio of alternative investments"

Linkedin profile

修改

LinkedIn有一个API,但由于某种原因,下面只返回前两个经验位置,没有其他项目(如教育,项目)。因此刮刮方法。

library("Rlinkedin")
auth = inOAuth(application_name, consumer_key, consumer_secret)
getProfile(auth, connections = FALSE, id = NULL) # returns very limited data

1 个答案:

答案 0 :(得分:0)

您正在做出不必要的困难......您需要做的就是在从Linkedin获取OAuth 2.0令牌后向https://api.linkedin.com/v1/people/~?format=json发出GET请求。在R中,您可以使用jsonlite

执行此操作
library(jsonlite)
linkedin <- fromJSON('https://api.linkedin.com/v1/people/~?format=json')
position <- linkedin$headline

您的oauth令牌必须具有'r_basicprofile'成员权限。

相关问题