python - Python从img打印URL +进入新页面
问题描述
我想在链接末尾的变量中输入下一页链接。
我是 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])
推荐阅读
- ios - 请问,如果iOS设备上的屏幕打开或关闭,我如何使用FireMonkey?
- python - 射线 + cross_val_score
- ruby-on-rails - 在 rails 中编辑表单 - 没有路线匹配 [PUT]
- javascript - 水平导航栏下拉菜单中出现双边框
- node.js - 如果不发送图像,我怎么能在我的用户上实现默认图像?
- flutter - flutter_local_notifications 不适用于 ios,但适用于 android
- mariadb - 我缺少什么语法?
- python - Bash (Cygwin) 无法识别 Python 模块
- symfony - 不支持内容类型 \"text/plain\"
- google-cloud-platform - GCP 中自定义服务帐号的自定义 IAM 策略绑定