我有这段代码:
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']