【发布时间】:2018-05-17 19:10:50
【问题描述】:
我在图片标签中有一个包含多个 id 的字符串:
<img id="webfast-uhyubv" alt="" data-type="image" id="comp-jefxldtzbalatamediacontentimage" src="http://webfast.co/images/webfast-logo.png" />
soup = bs4.BeautifulSoup(webpage,"html.parser")
images = soup.findAll('img')
for image in images:
print image
以上代码只返回id=comp-jefxldtzbalatamediacontentimage
更换
soup = bs4.BeautifulSoup(webpage,"html.parser")
与
soup = bs4.BeautifulSoup(webpage,"lxml")
返回第一个id webfast-uhyubv
但是,我想按照它们在输入行中存在的顺序获取两个 ID。
【问题讨论】:
-
这段代码只获取第一个 id 而不是第二个
-
@Rachit 它取决于解析器。
标签: python beautifulsoup html-parsing