【发布时间】:2020-09-15 19:03:16
【问题描述】:
我有来自网站的代码,我想在其中找到并获取图像的路径,我的意思是来自 src 标记中的 img 的值。问题的核心是标签之间的图像路径:wphimage 和 .jpg 扩展。
代码下方:
<p>
<wphimage data="{'Copyright':'John Smith','Alignment':'left','ImageVersion':'conductorportraitlong'}">
<span style="display:block; float:left;" class="DIV_imageWrapper">
<a data-lightview-title="John Smith" class="lightview" href="//path/to/image/web.jpg"">
<img src="//path/to/image/web.jpg" alt="Name">
</a>
<a class="A_copyright" href="javascript:;">© <span>Terry Linke</span></a>
<a href="javascript:;">≡ <span>John Smith</span></a>|
<a class="A_zoom lightview" href="//path/to/image/web.jpg" data-lightview-title="Dietfried Gürtler" data-lightview-caption="Terry Linke">+ </a>
</span>
</wphimage>
Text here...
</p>
我试过了:
wphimage = re.findall(r'\S+\.jpg', text)
但我还得到了另一个值,来自不同的标签,然后是 <img>。
【问题讨论】:
-
使用这里提到的beautifulsoup:stackoverflow.com/questions/43982002/…