-1

Okay so we all know their is many tools that tell you if a website is up down or available, but I want to make a tool that check for pages in a website. Example: Website www.Example.com is up, but does page www.Example.com/test.html exist?

The program will take a list from a text file to try, the text file will have:

games cpanel signup index example join-us

etc...

My program output should be like (if it is in batch): Press 1 to start Starting... Online pages: -cpanel -games -joinus etc... If it can't be done in batch or python, what other languages can it be done through? Thanks very much :)

Cyber Shadow
  • 100
  • 1
  • 11
  • It can be programmed natively in python as well as in lots of other languages or you can use any of the many command line utilities available on the internet *to check specific urls*. The question is either too broad or vague or doesn't belong to stackoverflow. – wOxxOm Sep 06 '15 at 11:37
  • I searched A LOT about it in many forums but got nothing. Do you know where I can find w tutorial or sample program like it? thanks @wOxxOm – Cyber Shadow Sep 06 '15 at 12:03
  • Duplicate of [Python script to see if a web page exists without downloading the whole page?](http://stackoverflow.com/questions/6471275/python-script-to-see-if-a-web-page-exists-without-downloading-the-whole-page) (it took 5 seconds to google for `python check if page exists`). – wOxxOm Sep 06 '15 at 12:13
  • @wOxxOm Well this is a start but read my post again. I want to import them from a text file and give a final result of pages online :) Thanks anyways :) – Cyber Shadow Sep 06 '15 at 13:00
  • well that doesn't make this question any more valid or suitable for stackoverflow as it still exhibits zero research effort regardless of your claims otherwise. – wOxxOm Sep 06 '15 at 13:08
  • @wOxxOm Well if you don't wont to answer, it is no problem, just don't say it isn't suitable... – Cyber Shadow Sep 06 '15 at 16:40
  • I'm just stating the obvious. You can read the rules under Help link. – wOxxOm Sep 06 '15 at 18:39

2 Answers2

1

check winhttpjs.bat - it will set the http response code of a http request to the errorlevel:

@echo off
call winhttpjs.bat http://google.com -saveto con >nul
if errorlevel 200 if not errorlevel 300 echo site is available
npocmaka
  • 55,367
  • 18
  • 148
  • 187
  • Well thanks but I said I don't want to check a site I want to check a page in a site (like http://google.com/register ) – Cyber Shadow Sep 06 '15 at 12:02
  • @CyberShadow - google.com/register returns 404 for me so the script will work correctly.With IF conditions you can improve the logic of the examples. – npocmaka Sep 06 '15 at 12:12
0

I think this is what you're looking for:

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"

test it using a pages.txt file containing something like this:

search
page
plus
signin
account
security
lol
about
someotherpage.html
v1k45
  • 8,070
  • 2
  • 30
  • 38
  • Thanks that is exactly what I am looking for. Just two questions, is this the full program? And can I make it give a full list at the end with just the pages that worked? Thanks again :) – Cyber Shadow Sep 06 '15 at 16:39
  • Yes, it is the full program. Yes, you can do the same by creating a list and writing the urls into a file. – v1k45 Sep 06 '15 at 17:20
  • I am a noob in python and I don't know advanced things. Can you please help me? I googled but can't get a straight answer. @v1k45 – Cyber Shadow Sep 06 '15 at 18:16
  • If it is so, then instead of building the thing directly, learn python basics first. feel free to mark the answer as correct if it helped you :) – v1k45 Sep 06 '15 at 18:43