开发者

Get the content of a tag with beautiful soup

开发者 https://www.devze.com 2023-02-14 14:17 出处:网络
I have this html: <a href=\"/watch?gl=US&amp;client=mv-google&amp;hl=en&amp;v=0C_yXOhJxWg\">Miss Black OCU 2011</a开发者_StackOverflow中文版>

I have this html:

<a href="/watch?gl=US&amp;client=mv-google&amp;hl=en&amp;v=0C_yXOhJxWg">Miss Black OCU 2011</a开发者_StackOverflow中文版>

My program reads a html file, and above is the chunk of that file. How do I extract "Miss Black OCU 2011" using BeautifulSoup in python.


Here's a quick fix:

>>> from BeautifulSoup import BeautifulSoup as BS
>>> soup = BS('<a href="/watch?gl=US&amp;client=mv-google&amp;hl=en&amp;v=0C_yXOhJxWg">Miss Black OCU 2011</a>')
>>> tags = soup.findAll('a', href=True)
>>> for tag in tags: tag.renderContents() 
'Miss Black OCU 2011'
>>> 
0

精彩评论

暂无评论...
验证码 换一张
取 消