#-*-コーディング:utf-8-*- "" " 作成日 :Mar 10 21:22:22 2021 @author:kimol_love&solar2030 >>>>>>>>このコードは、彼のブログにあるkimol_loveのコードに基づいて設計されています。 、https://blog.csdn.net/kimol_justdo/article/details/112996678?spm = 1001.2014.3001.5501彼に感謝します。ここでは、[for]コマンドを使用して、一連の論文をon-でダウンロードできるようにしました。準備する必要があるのは、紙のタイトルのリストを含むテキストファイルだけです。同時に、紙のタイトルの「/」に関連するバグを解決しました。ファイル名に「/」を使用できないため、問題が発生する可能性があります。 。【str.replace】コマンドを使用すると、「/」を「_」に置き換えることができます。たとえば、バグを修正できます。 >>>>>>>> "" " import os import time import requests from bs4 import BeautifulSoup from tkinter.filedialog import askopenfilename import matplotlib.pyplot as plt import numpy as np path_and_name = askopenfilename(title = 'ペーパーリスト:タイトルまたはdoi'、filetypes = [( 'TXT'、 '* .txt')] 、 initialdir = 'D:\\') data = [] with open(path_and_name)as txt_file: line = txt_file.readlines() for i、rows in enumerate(line): if i in range(0、len(line) ): data.append(rows) print(data [0]) def search_article(artName): '' ' 搜索论文 --------------- 追加入:论文名 ----- ---------- 出:搜索結果(如果没有返回 ""、それ以外の場合はPDFリンクに戻る) '' ' url = 'https://www.sci-hub.ren/' headers = {'User-Agent': 'Mozilla / 5.0(Windows NT 6.3; Win64; x64; rv:84.0)Gecko / 20100101 Firefox / 84.0'、 'Accept': 'text / html、application / xhtml + xml、application / xml; q = 0.9、image / webp、* / *; q = 0.8'、 'Accept-Language': 'zh-CN、zh; q = 0.8、zh-TW; q = 0.7、zh-HK; q = 0.5、en-US; q = 0.3、en; q = 0.2 '、 ' Accept-Encoding ':' gzip、deflate、br '、 ' Content -タイプ ':' application / x-www-form-urlencoded '、 ' Content-Length ':' 123 '、 ' Origin ':' https://www.sci-hub.ren '、 '接続': 'キープアライブ'、 'アップグレード-安全でない-要求': '1'} data = {' sci-hub-plugin-check ':' '、 ' request ':artName} res = requests.post(url、headers = headers、data = data) html = res.text soup = BeautifulSoup(html、 'html.parser') iframe = soup.find(id = 'pdf') if iframe == None:#対応する記事が見つかりませんでした return '' else: downUrl = iframe ['src'] 'http'がdownUrlにない場合: downUrl = 'https:' + downUrl return downUrl def download_article(downUrl): '' ' 紙のリンクに従って記事をダウンロードします --------------- ----- --input :papers link ---------------------- output:PDF file binary '' ' ヘッダー= {'ユーザーエージェント ':'Mozilla / 5.0(Windows NT 6.3; Win64; x64; rv:84.0)Gecko / 20100101 Firefox / 84.0 '、 _____ _____ _____ _ _ _ _ ____ / ____ | / ____ | _ _ | | | | | | | | _ \ | (___ | | | | ______ | | __ | | | | | | _)| \ ___ \ | | | | ______ | __ | | | | _ < ____)| | ____ _ | | _ | | | | | __ | | | _)| | _____ / \ _____ | _____ | | _ | | _ | \ ____ / | ____ / '' ' print(title) if __name__ ==' __main __ ' :#while True: I = [] for ii in range(len(data)): welcome()#request = input ( '请入入URL、PMID、DOIまたは著者论文PWM题:') request = data [ii] .strip() title = request.replace( "/"、 "_") str1 = str(ii)+ '-' title1 = str1 + title print( ' 搜索中...')downUrl = search_article(request) if downUrl == '': print( '関連する用紙が見つかりませんでした。もう一度検索してください!') I.append( '0') else: print( '論文リンク:%s'%downUrl) print( 'ダウンロード中...') pdf = download_article(downUrl)#ドキュメント ストレージディレクトリD:\ doc_E \ papers \ with open( 'D:\ doc_E \ papers \%s.pdf'%title1、 'wb')as f: f.write(pdf) print( '---ダウンロード完了---') I .append ( '1')time.sleep(0.8) print( '完全な統計をダウンロード:%s'、I)
2021-03-10Pythonバッチダウンロード資料PDF
おすすめ
転載: blog.csdn.net/you_us/article/details/114646697
おすすめ
ランキング