2014-10-10 88 views

回答

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>]