每次如何请求URL更改一些数字?

时间:2019-07-16 11:54:19

标签: python function url

例如,我有以下URL:

http://web.ca.com/y/d.ASP?id=1

我想每次请求该URL时都需要更改ID。

如何通过Python做到这一点。

  

结果

     

http://web.ca.com/y/d.ASP?id=2

     

http://web.ca.com/y/d.ASP?id=3

     

http://web.ca.com/y/d.ASP?id=4

1 个答案:

答案 0 :(得分:0)

您可以使用requests

import requests

for x in range(0,10): # Here you define the amount of tries you're going to check    
   r = requests.get('http://web.ca.com/y/d.ASP?id={}'.format(x)) # this would be the loop value    
   print(r.status_code) # this would be the http response code