如何在python中找到一个页面?

Dav*_*erg -2 python

我想要做的是在python中找到一个特定的页面,我的意思是:例如,如果存在它会输出它,如果不存在那么它就不会.我知道但问题是,找到网站页面的功能是什么?喜欢.我想找/ test /如果它不存在,它会说"/ test /在网站上不存在:test.com"

我需要做什么?

ale*_*cxe 5

只需检查页面的HTTP状态代码即可.使用请求的示例:

>>> import requests
>>> response = requests.get('http://google.com/test')
>>> response.status_code
404
>>> if response.status_code == 404:
...     print "/test/ does not exist on the website: google.com"
... 
/test/ does not exist on the website: google.com
Run Code Online (Sandbox Code Playgroud)