<a title="dynamic link" href="test.php">text</a>
我如何才能像上面的示例那样仅获取带有标题标签的标签?
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>]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.