scholarly项目技术文档
scholarly
是一个Python模块,它使得从Google Scholar获取作者和出版物信息变得简单直观,无需解决验证码问题。
安装指南
您可以通过以下两种方法之一来安装scholarly
:
-
使用Conda
执行以下命令以通过
conda-forge
通道安装:conda install -c conda-forge scholarly
-
使用pip
获取最新版本,可以运行:
pip3 install scholarly
或者直接从GitHub仓库安装最新代码:
pip3 install -U git+https://github.com/scholarly-python-package/scholarly.git
对于包含Tor支持的可选安装,您可以这样做(不适用于Conda):
pip3 install scholarly[tor]
请注意,频繁更新是推荐的,因为scholarly
遵循语义化版本控制(Semantic Versioning),确保您的代码兼容性。
项目的使用说明
快速开始
在成功安装scholarly
后,您就可以开始查询作者信息了。下面的例子展示如何检索并打印一个作者的详细资料及其发表作品的标题。
from scholarly import scholarly
# 搜索作者
search_query = scholarly.search_author('Steven A Cholewiak')
first_author_result = next(search_query)
scholarly.pprint(first_author_result)
# 填充作者详细信息并打印
author = scholarly.fill(first_author_result)
scholarly.pprint(author)
# 打印作者的作品标题
publication_titles = [pub['bib']['title'] for pub in author['publications']]
print(publication_titles)
使用API
scholarly
提供了丰富的API来操作数据。例如,填充更多作者详情和查看引用情况:
# 查看首个作品的引用文献
first_publication_filled = scholarly.fill(author['publications'][0])
citations = [citation['bib']['title'] for citation in scholarly.citedby(first_publication_filled)]
print(citations)
API使用文档
完整API参考请查阅官方文档的scholarly.html页面。
重要提示
频繁执行某些类型查询时,如scholarly.citedby
或scholarly.search_pubs
,可能会被Google Scholar限制访问。为了避免IP被封,应当使用代理服务。详情见文档中的"使用代理"部分。
测试
验证安装是否成功的简单方式是运行测试脚本:
python3 test_module.py
或者使用unittest模块:
python3 -m unittest -v test_module.py
以上就是对scholarly
项目的简要技术文档。详细功能和高级用法请深入阅读其官方文档。记住,在使用过程中设置代理以保障稳定性和避免潜在的访问限制是关键。
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考