casoa_show.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
中科院 OA 期刊论文详细信息获取脚本
"""
import argparse
import requests
from bs4 import BeautifulSoup
def get_paper_details(doi):
"""
获取论文详细信息
Args:
doi: 论文 DOI
Returns:
论文详细信息
"""
url = f"https://www.oaj.cas.cn/article/{doi}"
try:
response = requests.get(url)
response.raise_for_status()
soup = BeautifulSoup(response.text, 'html.parser')
# 提取标题
title_elem = soup.find('h1', class_='article-title')
title = title_elem.text.strip() if title_elem else "No title"
# 提取作者
authors_elem = soup.find('div', class_='authors')
authors = authors_elem.text.strip() if authors_elem else "No authors"
# 提取摘要
abstract_elem = soup.find('div', class_='abstract')
abstract = abstract_elem.text.strip() if abstract_elem else "No abstract"
# 提取期刊信息
journal_elem = soup.find('div', class_='journal-header')
journal = journal_elem.text.strip() if journal_elem else "No journal"
# 提取出版日期
date_elem = soup.find('div', class_='pub-date')
pub_date = date_elem.text.strip() if date_elem else "No date"
# 提取关键词
keywords_elem = soup.find('div', class_='keywords')
keywords = keywords_elem.text.strip() if keywords_elem else "No keywords"
return {
"title": title,
"authors": authors,
"abstract": abstract,
"journal": journal,
"pub_date": pub_date,
"keywords": keywords,
"url": url
}
except requests.exceptions.RequestException as e:
print(f"获取论文信息失败: {e}")
return None
def main():
parser = argparse.ArgumentParser(description="获取中科院 OA 期刊论文详细信息")
parser.add_argument("doi", help="论文 DOI (格式: 10.1360/SSPMA20230001)")
args = parser.parse_args()
print(f"获取论文信息: {args.doi}")
details = get_paper_details(args.doi)
if details:
print(f"\n标题: {details['title']}")
print(f"\n作者: {details['authors']}")
print(f"\n期刊: {details['journal']}")
print(f"\n出版日期: {details['pub_date']}")
print(f"\n关键词: {details['keywords']}")
print(f"\n摘要:\n{details['abstract']}")
print(f"\n链接: {details['url']}")
else:
print("未能获取论文详细信息")
if __name__ == "__main__":
main()