一个Python包,与Internet存档的Wayback Machine API接口。存档页面并轻松检索存档页面。

waybackp的Python项目详细描述


任性

contributions welcomeBuild StatuscodecovDownloadsReleaseCodacy BadgeMaintainabilityCodeFactormade-with-pythonpypiPyPI - Python VersionMaintenanceRepo sizeLicense: MIT

Wayback Machine

Waybackpy是一个与Internet ArchiveWayback MachineAPI接口的Python包。存档网页和检索存档网页容易。在

目录

安装

使用pip

pip install waybackpy

或者使用git从这个存储库直接访问。在

^{pr2}$

使用

作为Python包

捕获aka使用save()保存url

importwaybackpyurl="https://en.wikipedia.org/wiki/Multivariable_calculus"user_agent="Mozilla/5.0 (Windows NT 5.1; rv:40.0) Gecko/20100101 Firefox/40.0"waybackpy_url_obj=waybackpy.Url(url,user_agent)archive=waybackpy_url_obj.save()print(archive)
https://web.archive.org/web/20201016171808/https://en.wikipedia.org/wiki/Multivariable_calculus

在您的浏览器中尝试一下@https://repl.it/@akamhy/WaybackPySaveExample

使用archive\u URL检索URL的存档文件

importwaybackpyurl="https://www.google.com/"user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:40.0) Gecko/20100101 Firefox/40.0"waybackpy_url_obj=waybackpy.Url(url,user_agent)archive_url=waybackpy_url_obj.archive_urlprint(archive_url)
https://web.archive.org/web/20201016153320/https://www.google.com/

在您的浏览器中尝试一下@https://repl.it/@akamhy/WaybackPyArchiveUrl

使用oldest()检索URL的最旧存档文件
importwaybackpyurl="https://www.google.com/"user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:40.0) Gecko/20100101 Firefox/40.0"waybackpy_url_obj=waybackpy.Url(url,user_agent)oldest_archive_url=waybackpy_url_obj.oldest()print(oldest_archive_url)
http://web.archive.org/web/19981111184551/http://google.com:80/

在您的浏览器中尝试一下@https://repl.it/@akamhy/WaybackPyOldestExample

使用newest()检索URL的最新存档文件
importwaybackpyurl="https://www.facebook.com/"user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:39.0) Gecko/20100101 Firefox/39.0"waybackpy_url_obj=waybackpy.Url(url,user_agent)newest_archive_url=waybackpy_url_obj.newest()print(newest_archive_url)
https://web.archive.org/web/20201016150543/https://www.facebook.com/

在您的浏览器中尝试一下@https://repl.it/@akamhy/WaybackPyNewestExample

检索Availability API请求的JSON响应

importwaybackpyurl="https://www.facebook.com/"user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:39.0) Gecko/20100101 Firefox/39.0"waybackpy_url_obj=waybackpy.Url(url,user_agent)json_dict=waybackpy_url_obj.JSONprint(json_dict)
{'url':'https://www.facebook.com/','archived_snapshots':{'closest':{'available':True,'url':'http://web.archive.org/web/20201016150543/https://www.facebook.com/','timestamp':'20201016150543','status':'200'}}}

在您的浏览器中尝试一下@https://repl.it/@akamhy/WaybackPyJSON

使用near()检索接近指定年、月、日、小时和分钟的存档文件

fromwaybackpyimportUrluser_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Firefox/38.0"url="https://github.com/"waybackpy_url_obj=Url(url,user_agent)# Do not pad (don't use zeros in the month, year, day, minute, and hour arguments). e.g. For January, set month = 1 and not month = 01.
github_archive_near_2010=waybackpy_url_obj.near(year=2010)print(github_archive_near_2010)
https://web.archive.org/web/20101018053604/http://github.com:80/
github_archive_near_2011_may=waybackpy_url_obj.near(year=2011,month=5)print(github_archive_near_2011_may)
https://web.archive.org/web/20110518233639/https://github.com/
github_archive_near_2015_january_26=waybackpy_url_obj.near(year=2015,month=1,day=26)print(github_archive_near_2015_january_26)
https://web.archive.org/web/20150125102636/https://github.com/
github_archive_near_2018_4_july_9_2_am=waybackpy_url_obj.near(year=2018,month=7,day=4,hour=9,minute=2)print(github_archive_near_2018_4_july_9_2_am)
^{pr21}$

包尚不支持第二个参数。我们鼓励您创建公关;)

在您的浏览器中尝试一下@https://repl.it/@akamhy/WaybackPyNearExample

使用Get()获取网页内容
importwaybackpygoogle_url="https://www.google.com/"User_Agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36"waybackpy_url_object=waybackpy.Url(google_url,User_Agent)# If no argument is passed in get(), it gets the source of the Url used to create the object.current_google_url_source=waybackpy_url_object.get()print(current_google_url_source)# The following chunk of code will force a new archive of google.com and get the source of the archived page.# waybackpy_url_object.save() type is string.google_newest_archive_source=waybackpy_url_object.get(waybackpy_url_object.save())print(google_newest_archive_source)# waybackpy_url_object.oldest() type is str, it's oldest archive of google.comgoogle_oldest_archive_source=waybackpy_url_object.get(waybackpy_url_object.oldest())print(google_oldest_archive_source)

在您的浏览器中尝试一下@https://repl.it/@akamhy/WaybackPyGetExample#main.py

使用total_archives()计算URL的总存档数

importwaybackpyURL="https://en.wikipedia.org/wiki/Python (programming language)"UA="Mozilla/5.0 (iPad; CPU OS 8_1_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B435 Safari/600.1.4"waybackpy_url_object=waybackpy.Url(url=URL,user_agent=UA)archive_count=waybackpy_url_object.total_archives()print(archive_count)# total_archives() returns an int
2516

在您的浏览器中尝试一下@https://repl.it/@akamhy/WaybackPyTotalArchivesExample

回程机器知道并已为域名存档的URL列表

  1. 如果设置了alive=True,则waybackpy将检查所有url以标识活动url。不要使用像谷歌这样的流行网站,否则会花太长时间。在
  2. 要包含来自子域的URL,请设置sundomain=True
importwaybackpyURL="akamhy.github.io"UA="Mozilla/5.0 (iPad; CPU OS 8_1_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B435 Safari/600.1.4"waybackpy_url_object=waybackpy.Url(url=URL,user_agent=UA)known_urls=waybackpy_url_object.known_urls(alive=True,subdomain=False)# alive and subdomain are optional.print(known_urls)# known_urls() returns list of URLs
['http://akamhy.github.io',
'https://akamhy.github.io/waybackpy/',
'https://akamhy.github.io/waybackpy/assets/css/style.css?v=a418a4e4641a1dbaad8f3bfbf293fad21a75ff11',
'https://akamhy.github.io/waybackpy/assets/css/style.css?v=f881705d00bf47b5bf0c58808efe29eecba2226c']

在您的浏览器中尝试一下@https://repl.it/@akamhy/WaybackPyKnownURLsToWayBackMachineExample#main.py

使用命令行界面

保存

$ waybackpy --url "https://en.wikipedia.org/wiki/Social_media" --user_agent "my-unique-user-agent" --save
https://web.archive.org/web/20200719062108/https://en.wikipedia.org/wiki/Social_media

在您的浏览器中尝试一下@https://repl.it/@akamhy/WaybackPyBashSave

获取存档URL

$ waybackpy --url "https://en.wikipedia.org/wiki/SpaceX" --user_agent "my-unique-user-agent" --archive_url
https://web.archive.org/web/20201007132458/https://en.wikipedia.org/wiki/SpaceX

在您的浏览器中尝试一下@https://repl.it/@akamhy/WaybackPyBashArchiveUrl

最旧的存档文件

$ waybackpy --url "https://en.wikipedia.org/wiki/SpaceX" --user_agent "my-unique-user-agent" --oldest
https://web.archive.org/web/20040803000845/http://en.wikipedia.org:80/wiki/SpaceX

在您的浏览器中尝试一下@https://repl.it/@akamhy/WaybackPyBashOldest

最新存档

$ waybackpy --url "https://en.wikipedia.org/wiki/YouTube" --user_agent "my-unique-user-agent" --newest
https://web.archive.org/web/20200606044708/https://en.wikipedia.org/wiki/YouTube

在您的浏览器中尝试一下@https://repl.it/@akamhy/WaybackPyBashNewest

获取可用性API的JSON数据

^{pr31}$
{'archived_snapshots':{'closest':{'timestamp':'20201007132458','status':'200','available':True,'url':'http://web.archive.org/web/20201007132458/https://en.wikipedia.org/wiki/SpaceX'}},'url':'https://en.wikipedia.org/wiki/SpaceX'}

在您的浏览器中尝试一下@https://repl.it/@akamhy/WaybackPyBashJSON

档案总数

$ waybackpy --url "https://en.wikipedia.org/wiki/Linux_kernel" --user_agent "my-unique-user-agent" --total
853

在您的浏览器中尝试一下@https://repl.it/@akamhy/WaybackPyBashTotal

近期存档

$ waybackpy --url facebook.com --user_agent "my-unique-user-agent" --near --year 2012 --month 5 --day 12
https://web.archive.org/web/20120512142515/https://www.facebook.com/

在您的浏览器中尝试一下@https://repl.it/@akamhy/WaybackPyBashNear

获取源代码

^{pr35}$

在您的浏览器中尝试一下@https://repl.it/@akamhy/WaybackPyBashGet

获取回程机器知道的域的所有url

  1. 您可以添加“--alive”标志以仅获取活动链接。在
  2. 您可以添加“--subdomain”标志来添加子域。在
  3. “--alive”和“--subdomain”标志可以同时使用。在
  4. 所有链接都将保存在一个文件中,并且该文件将在当前工作目录中创建。在
pip install waybackpy

# Ignore the above installation line.

waybackpy --url akamhy.github.io --user_agent "my-user-agent" --known_urls
# Prints all known URLs under akamhy.github.io


waybackpy --url akamhy.github.io --user_agent "my-user-agent" --known_urls --alive
# Prints all known URLs under akamhy.github.io which are still working and not dead links.


waybackpy --url akamhy.github.io --user_agent "my-user-agent" --known_urls --subdomain
# Prints all known URLs under akamhy.github.io inclusing subdomain


waybackpy --url akamhy.github.io --user_agent "my-user-agent" --known_urls --subdomain --alive
# Prints all known URLs under akamhy.github.io including subdomain which are not dead links and still alive.

在你的眉毛上试试这个er@{a58}

测试

Here

要在本地运行测试,请执行以下操作:

pip install -U pytest
pip install codecov
pip install pytest pytest-cov
cd tests
pytest --cov=../waybackpy
python -m codecov #For reporting coverage on Codecov

依赖关系

没有,只是预装了python standard libraries。在

包装

  1. 增量版本。在

  2. 生成包python setup.py sdist bdist_wheel。在

  3. 签名并上载包twine upload -s dist/*。在

许可证

根据麻省理工学院的许可证发布。看到了吗 license了解详细信息。在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
来自偏移量的java JavaPairInputStream流   gzip Java TarInputStream读取tar的文件名。包含另一个tar的gz文件。gz文件   如何在Linux shell脚本中确定和使用实际的java路径   java请求太多FirebaseError   java错误json解析   java在localserver上发送安卓应用程序的输出   JavaSpring:启动和停止webapplication时更新DBtable条目   java如何使用JavaFX在矩形处设置文本?   java SQL查询在Hibernate中出现异常   java我无法使用javamail代码通过outlook(hotmail帐户)配置发送邮件,但在gmail中工作正常   java是不同的持久性。测试运行/JPA装置的xml属性   无头Eclipse的java导出战   使用ContentVersionStrategy的java Spring引导缓存禁止使用gzip进行资源压缩   java如何获取计算机的设备令牌?   图像文件的java ImageInfo不包含有效值   继承强制在Java中使用基类方法