从多个联机图书源查找图书下载URL
pybooks的Python项目详细描述
安装
$ pip install pybooks
用法
简单用法
from pybooks.pbook import Pbooks
pbook = Pbooks( author='jerome',
title='elements of statistic',
weights=(9, 1))
pbook.main()
参数weights
用于计算找到的所有项和最终选择的url的准确性。例如,weights
的(9, 1)
将比title对作者准确性更重要,因此结果更有可能使author的名称与输入更相似。默认权重为(1, 1)
可选参数有show_result: Print the result at the end or not
、threshold: Only print result with accuracy higher than threshold
和log: Show process while running or not
等。在代码文档中可以找到更多参数。
可以通过编辑文件PyBoox/SuthCE.jSON修改和添加其他源,并按照文件中的现有格式。
sources.json格式,规则
示例: Library Genesis with elements of statistics as search term
我们在url中只需要以下组件:request: ?req=...
、delimiter: + (elements+of+statistics)
、pagination: page=...
和term_concatenation: & (req=...&page=...)
INSIDE SOURCES.JSON
URL: main url without search terms
URL_RULES: dictionary contains keys and values as search rules.
HTML_RULES: Contains nested dictionary represent necessary components to conduct searches such as tags, attributes for titles, authors, rows and page body
.POSITION: The position of the that element in the row if there are other similar elements with similar tag and attributes, leave as null if it is unique
.TAG: The tag of the desired element
.ATTRIBUTE: Attributes of the tag, for exanple: {"class": "id", "...": "..", ...}. Leave the value of a key as true if an attribute has no value
命令行用法
可以直接从命令行使用包
示例:搜索一本书名为“统计学习要素”和作者为“Jerome Friedman”的书
您可以将pbook.exe添加到环境变量中,并通过此命令从命令行使用它,%PATH%
作为指向pybooks目录(文件夹)的路径,通常可以在\Python{version}\Lib\pybooks
中找到。
setx PATH "%PATH%
pbook -a "jerome friedman" -t "elements of statistical learning"
OPTIONAL ARGUMENTS -h, --help show this help message and exit -a AUTHOR, --author AUTHOR Author of the book you want to find -t TITLE, --title TITLE Title of the book you want to find -w WEIGHTS, --weights WEIGHTS Assign author and title weight to the final accuracy calculation -th THRESHOLD, --threshold THRESHOLD Only get results above the threshold amount -l LOG, --log LOG Print out the process -s SHOW, --show SHOW Show result at the end of running -br BREAK_AT, --break-at BREAK_AT Stop when encounter a book with accuracy higher than or equal to this number -m METHOD, --method METHOD Choose a book evaluation method
许可证
麻省理工学院