Sim*_*ely 6 html python beautifulsoup html-parsing
我find_all()在我的BeautifulSoup代码中打电话.这目前可以为我提供所有图像,但是如果我只想定位其中包含"占位符"子字符串的图像,src我该怎么办呢?
for t in soup.find_all('img'): # WHERE img.href.contains("placeholder")
Run Code Online (Sandbox Code Playgroud)
ale*_*cxe 14
您可以在关键字参数中传递一个函数src:
for t in soup.find_all('img', src=lambda x: x and 'placeholder' in x):
Run Code Online (Sandbox Code Playgroud)
或者,正则表达式:
import re
for t in soup.find_all('img', src=re.compile(r'placeholder')):
Run Code Online (Sandbox Code Playgroud)
或者,而不是find_all(),使用select():
for t in soup.select('img[src*=placeholder]'):
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7670 次 |
| 最近记录: |