需要相关学科、主题的论文元数据做一些分析,arXiv开源,容易获取。
显示选择了考虑用arXiv的api去实现,相关手册见👉arXiv-api
但貌似每次我都被卡在3000条数据就停止了,所以我选择用传统的lxml,bs4直接爬取,但仍然被限制爬取10000条。
直接上完整代码,后面解释
from lxml import html
import requests
import re
import math
import csv
from bs4 import BeautifulSoup
import time
def get_total_results(url):
"""获取总结果数"""
response = requests.get(url)
tree = html.fromstring(response.content)
result_string = ''.join(tree.xpath('//*[@id="main-container"]/div[1]/div[1]/h1/text()')).strip()
match = re.search(r'of ([\d,]+) results', result_string)
if match:
total_results = int(match.group(1).replace(',', ''))
return total_results
else:
print("没有找到匹配的数字。"
使用Python爬取arXiv论文元数据:解决API限制与手动抓取

最低0.47元/天 解锁文章
289

被折叠的 条评论
为什么被折叠?



