Beautiful Soup从element获取第二个属性

时间:2017-02-23 20:29:10

标签: beautifulsoup

我有这段代码:

all_cells = result.find_all('div')
test = all_cells[1].find('a')

通常会返回此行

<a data-toggle='tooltip' data-placement='bottom' data-html='true' title="<img src='https://l.jpg'>" href='details.php?id=234' title='sometext'><b>anothertext</b></a>

我想获得第二个“title”属性的内容(在我的示例中为 sometext ),但也要考虑有时缺少第一个“title”属性。例如,当缺少第一个属性时,这将返回我需要的信息。

testok = test['title']

0 个答案:

没有答案