Spaces:
Sleeping
Sleeping
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 篩選 | |