<a title="dynamic link" href="test.php">text</a>
如何才能抓住唯一具有上述示例标题标签的内容?
答案 0 :(得分:1)
You can use select
method with commonly-used css selector:
>>> from bs4 import BeautifulSoup
>>> html = '''
... <html>
... <body>
... <a title="dynamic link" href="test1.php">text</a>
... <a href="test2.php">text</a>
... </body>
... </html>
... '''
>>> soup = BeautifulSoup(html)
>>> soup.select('a[title]')
[<a href="test1.php" title="dynamic link">text</a>]