Python通过更改url号进入新页面

Python通过更改url号进入新页面,python,Python,嗨,我需要使这个python代码循环页从1一直到5 ('') 如果他们对硒的任何方式都很酷,您可以在数字范围内循环添加,并将其用作参数 for i in range(1, 6): html = urlopen(f'https://test.com/index/{i}') bs = BeautifulSoup(html, 'html.parser') images = bs.find_all('img', {'src': re.compile('.jpg')}) f

嗨,我需要使这个python代码循环页从1一直到5

('')


如果他们对硒的任何方式都很酷,您可以在数字范围内循环添加,并将其用作参数

for i in range(1, 6):
    html = urlopen(f'https://test.com/index/{i}')
    bs = BeautifulSoup(html, 'html.parser')
    images = bs.find_all('img', {'src': re.compile('.jpg')})
    for image in images:
        print(image['src'].split('/')[-1].split('_')[0])

它与@Guy基本相同,但你也可以这样做

for num in range(1, 6):
    html = urlopen(f'https://test.com/index/%s'%num)
    bs = BeautifulSoup(html, 'html.parser')
    images = bs.find_all('img', {'src': re.compile('.jpg')})
    for image in images:
        print(image['src'].split('/')[-1].split('_')[0])

这种方法对范围(1,6)内的i不起作用:它只显示第1页+只打印第1页。这方面有什么帮助吗?或者像selenium这样的东西?你是使用了我所有的代码还是只使用了第一行?你需要使用数字作为参数,在你的代码中它被固定为1。是的,我使用了所有的代码没有工作对不起,我是新的it python可能你能给我举个例子吗?我确实使用了@Guy代码工作,但没有循环页面+只打印第1页,如以下代码
python for i范围(1,6):html=urlopen(f'https://test.com/index/1{i} )
我应该这样排第一吗^