python - Python beautifulsoup:从 img src 获取占位符
问题描述
在 BeautifulSoup 的帮助下,我尝试从主页读取图像的图像地址。在页面源文本中,我看到了图像的 URL。但是,如果我尝试使用find_all
BeautifulSoup 中的命令读取地址,我只会得到图像 URL 的占位符。
图片中的 URL 结构如下:
<a href="Young-Justice-(2019)/Young-Justice-(2019)-Issue-11/3"><br /><img src="mangas/Young Justice (2019)/Young Justice (2019) Issue 11/cw002.jpg" alt="" width="1200" height="1846" class="picture" /></a>
在 BeautifulSoup 我得到这个:
<img 0="" alt="" class="picture" height="" src="/pics/placeholder2.jpg" width=""/>]
我希望任何人都可以给我一个提示或为什么我得到一个占位符而不是原始图像 url。
我的代码:
import requests
from bs4 import BeautifulSoup as BS
from requests.exceptions import ConnectionError
def getimageurl(url):
try:
response = requests.get(url)
soup = BS(response.text, 'html.parser')
data = soup.find_all('a', href=True)
for a in data:
t = a.find_all('img', attrs={'class': 'picture'})
print(t)
except ConnectionError:
print('Cant open url: {0}'.format(url))
解决方案
推荐阅读
- java - 如何使用 ByteBuddy 读取 Java 类方法注解
- python - Django 每天午夜在后台更新一个静态 csv 文件
- python - 如何使用 pandas 找到每个主成分的前三个特征?
- javascript - 等待整个同步循环的 Javascript
- python - 可执行的 Python 脚本不会从 crontab 运行
- python - Python 请求返回 200 状态码但没有做我想做的事
- r - ggplot:一张图上有两条线,日期中断(y轴)
- haskell - 实例化某些对象(Haskell)
- java - 片段视图返回后执行的 Firebase 查询
- python - 当我想在 cartpaket 表中插入新数据时,我遇到了这个错误“无法分配“7”:“CartPaket.toko_id”必须是“Toko”实例”