0

If we have a URL :

https://www.example.com/123.html

I wish to check if other web pages are present by changing certain portion of URL , in this case we can do by changing numbers.

Hence :

https://www.example.com/124.html 

So how can i do it , say run a script , which checks presence of web pages in this directory by changing , in this case , last three numbers , say from 000 to 999 ?

Hemant Kumar
  • 141
  • 11
  • What code have you tried? You should have a look at Python's `range` function along with a `for` loop if you want to "trial-and-error" different URLs. – Aaron Christiansen Mar 14 '16 at 14:03
  • @OrangeFlash81 Thanks for replying buddy , yes thats exactly what i want , a "trial and error" , i will try using python range function , but just a offf question here DO we have any libraries that can do this by just inputting the URL and feeding them the ranges.? – Hemant Kumar Mar 14 '16 at 14:06
  • It's not a Python library, rather a program, but this is the sort of thing that [Burp Suite](https://portswigger.net/burp/) is for. – Aaron Christiansen Mar 14 '16 at 16:22

1 Answers1

0

For formatting the number, you can use format along with a format string in later versions of Python (>=2.7?) or x.zfill(3) in earlier versions. See this question.

For making requests in a loop:

import requests

for x in range(1000):
   page = requests.get('https://www.example.com/{0:03d}.html'.format(X))
   print(page.content)
Community
  • 1
  • 1
Josh Rumbut
  • 2,640
  • 2
  • 32
  • 43