利用python下載scihub成文獻為PDF操作
scihub是科研利器,這就不多說了,白嫖文獻的法門,一般采用的是網頁或者桌面程序,一般都會跳轉到網頁進行加載出文獻,但是這很不方便,畢竟全手動,這里無意中看到一個寫好的pip工具scihub2pdf ,于是試一下它手動威力,如果這能夠成功,也就是我們以后如果想批量下載也是沒問題的。
1.首先我們得安裝它:
pip install scihub2pdf
2.緊接著安裝npm和phantomjs,因為這個代碼里面使用了phantomjs
yum install npm
切換到國內源,威力網速給力,npm是nodejs的倉庫,我們類比成python的pip即可
npm config set registry https://registry.npm.taobao.org
安裝 phantomjs
npm install -g phantomjs
如果順利成功的話,就可以試一下這個工具了
3.scihub2pdf的使用
先來看一下使用幫助
[root@VM_0_9_centos ~]# scihub2pdf -husage: scihub2pdf [-h] [--input INPUTFILE] [--title] [--uselibgen] [--location LOCATION] [--txt] SciHub to PDF ---------------------------------------------------- Downloads pdfs via a DOI number, article title or a bibtex file, using the database of libgen(sci-hub). Given a bibtex file $ scihub2pdf -i input.bib Given a DOI number... $ scihub2pdf 10.1038/s41524-017-0032-0 Given a title... $ scihub2pdf --title An useful paper Arxiv... $ scihub2pdf arxiv:0901.2686 $ scihub2pdf --title arxiv:Periodic table for topological insulators ## Download from list of items Given a text file like ``` 10.1038/s41524-017-0032-0 10.1063/1.3149495 ..... ``` download all pdf’s ``` $ scihub2pdf -i dois.txt --txt ``` Given a text file like ``` Some Title 1 Some Title 2 ..... ``` download all pdf’s ``` $ scihub2pdf -i titles.txt --txt --title ``` Given a text file like ``` arXiv:1708.06891 arXiv:1708.06071 arXiv:1708.05948 ..... ``` download all pdf’s ``` $ scihub2pdf -i arxiv_ids.txt --txt ```----------------------------------------------------- @author: Bruno Messias @email: messias.physics@gmail.com @telegram: @brunomessias @github: https://github.com/bibcure/sci2pdfoptional arguments: -h, --help show this help message and exit --input INPUTFILE, -i INPUTFILE bibtex input file --title, -t download from title --uselibgen Use libgen.io instead sci-hub. --location LOCATION, -l LOCATION folder, ex: -l ’folder/’ --txt Just create a file with DOI’s or titles
我們可以粗略看到,這個不僅僅可以doi還可批量的doi寫在一個文件里,進行批量下載,更牛的是可以直接使用論文標題進行下載,這就理解為啥這里面需要想依賴phantomjs了,這玩意就是爬蟲用的。
我們來試一下:
[root@VM_0_9_centos ~]# scihub2pdf 10.1063/1.4991232
注意的是,這里需要修改源碼,因為用的鏈接不對,我們應該使用http://sci-hub.tw/而不是http://sci-hub.cc,在源碼(我自己的是在vim /opt/AN/lib/python3.7/site-packages/scihub2pdf/download.py修改的,根據自己pip安裝的路徑進行調整)的download.py下就可找到進行修改,因為cc這個鏈接已經用不了的。
還可以下載arxiv上的論文,比如
[root@VM_0_9_centos ~]# scihub2pdf arxiv:2003.02355
下載時間都是有點慢的,要等一會才能成功,因為都是訪問的國外的網站
以上這篇利用python下載scihub成文獻為PDF操作就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持好吧啦網。
相關文章: