我正在使用Beautifulsoup从网站中提取iframe
iframes=汤。全部找到('iframe')
我想找到iframe中包含2或3个单词的所有src标记
假设src链接如下"https://xyz.co/embed/TNagkx3oHj8/The.Tale.S001.true.72p.x264-QuebecRules"
我知道如何提取包含“xyz”的链接
srcs = []
iframes = soup.find_all('iframe')
for iframe in iframes:
try:
if iframe['src'].find('xyz')>=0: srcs.append(iframe['src'])
except KeyError: continue
我的问题是如何提取包含“xyz”等2个单词的所有链接 和“真”或3个字 这就像过滤器,如果这两个字不存在于该链接不要废掉它
您可以使用custom function来检查
src
是否包含您想要的所有单词。你知道吗例如,您可以使用以下内容:
演示:
输出:
注意:
如果任何
<iframe>
标记不包含src
属性,上述函数将引发错误。在这种情况下,将函数更改为:相关问题 更多 >
编程相关推荐