Python 从 img 打印 URL + 转到新页面

Python prints URL from img + going to new page

我想在 link 末尾的变量中输入下一页 link。

我是 Python 的新人:(

这是我的脚本:

from urllib.request import urlopen
from bs4 import BeautifulSoup
import re

html = urlopen('https://test.com/index/index/2')
bs = BeautifulSoup(html, 'html.parser')
images = bs.find_all('img', {'src':re.compile('.jpg')})
for image in images: 
    print(image['src']+'\n')

可在以下位置找到脚本输出: https://1.amazonaws.com/awer/adc/45521192_15642345066.jpg

我可以让它只打印 45521192 所以输出将是这样的:

45521192
45521193
45521194
45521195

当然可以,只需将 print(image['src']+'\n') 更改为:

print(image['src'].split('/')[-1].split('_')[0])