开发者

Get the content of a tag with beautiful soup

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜