如何使用R或Python通过Google Scholar查询下载学术论文的PDF

时间:2015-02-11 22:13:36

标签: python r pdf download google-scholar

我有一份我需要下载的学术论文标题列表。我想写一个循环来从网上下载他们的PDF文件,但找不到办法。

以下是我到目前为止所考虑的一步一步(答案是欢迎使用R或Python):

# Create list with paper titles (example with 4 papers from different journals)
titles <- c("Effect of interfacial properties on polymer–nanocrystal thermoelectric transport",
            "Reducing social and environmental impacts of urban freight transport: A review of some major cities",
            "Using Lorenz curves to assess public transport equity",
            "Green infrastructure: The effects of urban rail transit on air quality")

#Loop step1 - Query paper title in Google Scholar to get URL of journal webpage containing the paper
#Loop step2 - Download the PDF from the journal webpage and save in your computer

for (i in titles){
                  journal_URL <- query i in google (scholar)
                  download.file (url = journal_URL, pattern = "pdf",
                                 destfile=paste0(i,".pdf")                      
                 }

Complicators:

循环步骤1 - Google学术搜索的第一首歌应该是论文的原始网址。但是,我听说Google学术搜索对Bots有点挑剔,所以替代方法是查询Google并获取第一个URL(跳转它会带来正确的URL)

循环步骤2 - 有些论文是门控的,所以我想有必要包含身份验证信息(user = __,passwd = __)。但是,如果我正在使用我的大学网络,这种认证应该是自动的,对吗?

PS。我只需要下载PDF。我对获取文献计量信息(例如引文记录,h-index)不感兴趣。要获取文献计量数据,需要提供一些指导here (R users)here (python users)

1 个答案:

答案 0 :(得分:5)

Crossref有一个程序,发布者可以为该文章的全文版本链接提供元数据。不幸的是,对于像Wiley,Elsevier和Springer这样的发布商,他们可能会提供链接,但是您需要额外的权限来实际检索内容。有趣吗?无论如何,一些工作,例如,这适用于你的第二个标题,搜索crossref,然后获取全文的URL,如果提供,然后抓取xml,(优于PDF恕我直言)

titles <- c("Effect of interfacial properties on polymer–nanocrystal thermoelectric transport", "Reducing social and environmental impacts of urban freight transport: A review of some major cities", "Using Lorenz curves to assess public transport equity", "Green infrastructure: The effects of urban rail transit on air quality")

library("rcrossref")
out <- cr_search(titles[2])
doi <- sub("http://dx.doi.org/", "", out$doi[1])
(links <- cr_ft_links(doi, "all"))
$xml
<url> http://api.elsevier.com/content/article/PII:S1877042812005551?httpAccept=text/xml

$plain
<url> http://api.elsevier.com/content/article/PII:S1877042812005551?httpAccept=text/plain

xml <- cr_ft_text(links, "xml")
library("XML")
xpathApply(xml, "//ce:author")[[1]]
<ce:author>
   <ce:degrees>Prof</ce:degrees>
   <ce:given-name>Eiichi</ce:given-name>
   <ce:surname>Taniguchi</ce:surname>
</ce:author>