Spaces:
Sleeping
Sleeping
File size: 1,285 Bytes
92c0981 5d01bda 92c0981 5d01bda |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import requests
import xml.etree.ElementTree as ET
from datetime import datetime
def 抓取論文(關鍵字, 最大數量=10):
"""
從 arXiv 依關鍵字搜尋論文(最新)
"""
url = f"https://export.arxiv.org/api/query?search_query=all:{關鍵字}&start=0&max_results={最大數量}&sortBy=lastUpdatedDate"
res = requests.get(url)
root = ET.fromstring(res.content)
論文清單 = []
for entry in root.findall('{http://www.w3.org/2005/Atom}entry'):
論文清單.append({
"標題": entry.find('{http://www.w3.org/2005/Atom}title').text.strip(),
"作者": [author.find('{http://www.w3.org/2005/Atom}name').text for author in entry.findall('{http://www.w3.org/2005/Atom}author')],
"發表時間": entry.find('{http://www.w3.org/2005/Atom}published').text[:10],
"連結": entry.find('{http://www.w3.org/2005/Atom}id').text
})
return 論文清單
def 篩選論文依年份(論文清單, 起始, 結束):
"""
依年份篩選論文(年分區間)
"""
篩選 = []
for 論文 in 論文清單:
年份 = int(論文["發表時間"][:4])
if 起始 <= 年份 <= 結束:
篩選.append(論文)
return 篩選
|