Regular Expression problem

Justin Azoff justin.azoff at gmail.com
Thu Jul 13 20:54:23 EDT 2006


Justin  Azoff wrote:
> >>> from BeautifulSoup import BeautifulSoup
> >>> html='<link href="mystylesheet.css" rel="stylesheet" type="text/css">'
> >>> page=BeautifulSoup(html)
> >>> page.link.get('href')
> 'mystylesheet.css'

On second thought, you will probably want something like
>>> [link.get('href') for link in page.fetch('link',{'type':'text/css'})]
['mystylesheet.css']

which will properly handle multiple link tags.

-- 
- Justin




More information about the Python-list mailing list