一个Python库,用于从SCP wiki中获取数据。
scpscraper的Python项目详细描述
SCP刮板
一个小的Python库,用于从SCP wiki中获取数据。考虑到人工智能培训(即NLP模型)和数据集收集(用于外部项目scp的分类),并且有一些参数允许在这些应用程序中易于使用。在
下面是安装说明、如何使用此库的示例以及如何使用它的方法。我希望你能发现这个和我一样有用!在
示例代码
安装
scpscraper
可以通过pip install
安装。下面是我建议使用的命令,这样您就可以一直使用最新版本。在
pip3 install --upgrade scpscraper
基础知识
导入库
^{pr2}$获取SCP的名称
# Let's use 3001 (Red Reality) as an example.name=scpscraper.get_scp_name(3001)print(name)# Outputs "Red Reality"
尽可能多地获取有关SCP的详细信息
# Again using 3001 as an exampleinfo=scpscraper.get_scp(3001)print(info)# Outputs a dictionary with the# name, object id, rating, page content by section, etc.
有趣的东西
获取SCP的page-content
div HTML
作为参考,page-content
div包含了用户实际编写的内容,没有所有额外的Wikidot外部内容。在
# Once again, 3001 is the examplescp=scpscraper.get_single_scp(3001)# Grab the page-content div specificallycontent=scp.find_all('div',id='page-content')print(content)# Outputs "<div id="page-content"> ... </div>"
从multiplescp抓取HTML或信息
# Grab info on SCPs 000-099scpscraper.scrape_scps(0,100)# Same as above, but only grabbing Keter-class SCPsscpscraper.scrape_scps(0,100,tags=['keter'])# Grab 000-099 in a format that can be used to train AIscpscraper.scrape_scps(0,100,ai_dataset=True)
# Scrape the page-content div's HTML from SCP-000 to SCP-099# Only including this as an example, but scrape_scps_html() has# all the same options as scrape_scps().scpscraper.scrape_scps_html(0,100)
谷歌Colaboratory仅限使用
因为googlecolaboratory中包含了google.colab
模块,我们可以在那里做一些其他我们不能做的事情。在
将你的Google驱动器安装到Colaboratory虚拟机上
# Mounts it to the directory /content/drive/scpscraper.gdrive.mount()
抓取SCP info/HTML,然后复制到您的Google驱动器中
# Requires your Google Drive to be mounted at the directory /content/drive/scpscraper.scrape_scps(0,100,copy_to_drive=True)scpscraper.scrape_scps_html(0,100,copy_to_drive=True)
将其他文件复制到/来自您的Google Drive
# Requires your Google Drive to be mounted at the directory /content/drive/scpscraper.gdrive.copy_to_drive('example.txt')scpscraper.gdrive.copy_from_drive('example.txt')
计划的更新
未来可能会进行更新,使从任何网站抓取数据变得容易/可行,从而便于大量收集数据。在
链接到GitHub Repo
请考虑检查一下!您可以在GitHub Repo中报告问题、请求特性、为该项目贡献等。这是联系我了解与本项目有关的问题/反馈的最佳方式。在
https://github.com/JaonHax/scpscraper/
- 项目
标签: