如何知道网站中的特定页面是否关闭(批处理或Python)

2024-03-29 06:02:32 发布

您现在位置:Python中文网/ 问答频道 /正文

好吧,所以我们都知道他们有很多工具可以告诉你一个网站是上是下还是可用,但是我想做一个工具来检查网站中的页面。例子: 网站www.Example.com是向上的,但不向上翻页www.Example.com/test.html存在吗?你知道吗

程序将从文本文件中获取一个列表进行尝试,该文本文件将具有:

游戏 cpanel公司 注册 指数 例子 加入我们

等等

我的程序输出应该是(如果是成批的): 按1开始 启动。。。 联机页面: -cpanel公司 -游戏 -细骨 等。。。 如果不能在批处理或python中完成,那么可以通过哪些其他语言完成? 非常感谢:)


Tags: 工具test程序com游戏网站examplehtml
2条回答

检查winhttpjs.bat-它会将http请求的http响应代码设置为错误级别:

@echo off
call winhttpjs.bat http://google.com -saveto con >nul
if errorlevel 200 if not errorlevel 300 echo site is available

我想这就是你想要的:

import urllib2

u = 'http://www.google.com/'

pages =  open('pages.txt', 'r').readlines()

for page in pages:
        url = u+page
        try:
                req = urllib2.urlopen(url)
        except urllib2.HTTPError as e:
                if e.code == 404:
                        print url+" does not exists"
        else:
                print url+" exists"

使用包含以下内容的pages.txt文件进行测试:

search
page
plus
signin
account
security
lol
about
someotherpage.html

相关问题 更多 >