Python中如何爬取学术论文数据?求助相关问题
我想爬 https://www.sigops.org/sosp/sosp17/program.html 这个网站的所有论文,自己写的时候发现论文的链接和实际点开的链接不一样,想求助大神指点一下思路。
Python中如何爬取学术论文数据?求助相关问题
302 跳转吧,允许跳转应该就可以获取到了吧
要爬取学术论文数据,主要得选对目标网站和工具。常用的有arXiv、PubMed、Google Scholar(注意反爬)、知网等。这里给个arXiv的完整例子:
import requests
import feedparser
import pandas as pd
from time import sleep
def fetch_arxiv_papers(query, max_results=10):
"""从arXiv API获取论文数据"""
base_url = "http://export.arxiv.org/api/query"
params = {
'search_query': query,
'start': 0,
'max_results': max_results,
'sortBy': 'submittedDate',
'sortOrder': 'descending'
}
response = requests.get(base_url, params=params)
feed = feedparser.parse(response.content)
papers = []
for entry in feed.entries:
paper = {
'title': entry.title,
'authors': ', '.join(author.name for author in entry.authors),
'published': entry.published,
'summary': entry.summary[:200] + '...' if len(entry.summary) > 200 else entry.summary,
'pdf_link': next((link.href for link in entry.links if link.type == 'application/pdf'), None),
'arxiv_id': entry.id.split('/')[-1]
}
papers.append(paper)
sleep(0.5) # 礼貌性延迟
return pd.DataFrame(papers)
# 使用示例
if __name__ == "__main__":
# 搜索机器学习相关论文
df = fetch_arxiv_papers("cat:cs.LG", max_results=5)
print(f"获取到 {len(df)} 篇论文")
print(df[['title', 'authors', 'published']].head())
# 保存到CSV
df.to_csv('arxiv_papers.csv', index=False, encoding='utf-8-sig')
关键点:
- arXiv API直接提供结构化数据,比爬网页简单
- feedparser解析Atom/RSS格式很方便
- 加了sleep避免请求过快
- 数据存成DataFrame方便后续处理
其他网站可能需要用requests+BeautifulSoup或者Selenium。PubMed有E-utilities API,知网这类商业数据库需要特别注意版权和反爬措施。
简单说就是先找官方API,没有再用爬虫工具,注意遵守robots.txt。
比如
> curl ‘xxxxx/ft_gateway.cfm?id=3132758&ftid=1913909’ -L -o x.pdf
https://dl.acm.org/ft_gateway.cfm?id=3132785&ftid=1913904&dwn=1&CFID=998859838&CFTOKEN=94606726
会 302 跳转
跳转 到
http://delivery.acm.org/10.1145/3140000/3132785/p1-pei.pdf?ip=218.17.206.98&id=3132785&acc=OPENTOC&key=4D4702B0C3E38B35%2E4D4702B0C3E38B35%2E4D4702B0C3E38B35%2EC42B82B87617960C&CFID=998859838&CFTOKEN=94606726&acm=1509011719_65cbe92e4daaceece431448128d58a22
这个是 实际 的访问路劲
跳转中 会设置 cookie,
一般来说,用 requests 的自动跳转没有问题(默认自动跳转),但是 按我最近工作上的经验,自动跳转可能出问题,你可以 不让 自动 跳转,然后 获得 响应中 headers 中的 location,然后再构造请求。
你先用 requests 的 session 做,如果有问题,就 抓包,然后 设置 不允许 重定向,分步伪造请求。
ACM 目测加了 UA 检测,给你的爬虫套个 UA 就可以获得原始地址了(我已爬完 XD )

