简体   繁体   English

如何通过更改URL来检查网页的存在,请查看详细信息?

[英]How do I check presence of web pages by making changes to a URL, please see details?

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. 我希望通过更改URL的某些部分来检查是否存在其他网页,在这种情况下,我们可以通过更改数字来完成。

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 ? 那么,我该如何做呢,比如说运行一个脚本,该脚本通过更改后三个数字(例如从000更改为999)来检查此目录中网页的存在?

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. 要格式化数字,可以在更高版本的Python(> = 2.7?)或更低版本的x.zfill(3)中将format和格式字符串一起使用。 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM