Extract links for certain section only from blogspot using BeautifulSoup

Deadly 提交于 2019-12-01 13:37:16

If you don't necessarily need to use BeautifulSoup I think it would be easier to do something like this:

import feedparser

url = feedparser.parse('http://ellywonderland.blogspot.com/feeds/posts/default?alt=rss')
for x in url.entries:
    print str(x.link)

Output:

http://ellywonderland.blogspot.com/2011/03/my-vintage-pre-wedding.html
http://ellywonderland.blogspot.com/2011/02/pre-wedding-vintage.html
http://ellywonderland.blogspot.com/2010/12/tissue-paper-flower-crepe-paper.html
http://ellywonderland.blogspot.com/2010/12/menguap-menurut-islam.html
http://ellywonderland.blogspot.com/2010/12/weddings-idea.html
http://ellywonderland.blogspot.com/2010/12/kawin.html
http://ellywonderland.blogspot.com/2010/11/vitamin-c-collagen.html
http://ellywonderland.blogspot.com/2010/11/port-dickson.html
http://ellywonderland.blogspot.com/2010/11/ellys-world.html

feedparser can parse the RSS feed of the blogspot page and can return the data you want, in this case the href for the post titles.

you need add .get to the object:

print Objecta.get('href')

Example from http://www.crummy.com/software/BeautifulSoup/bs4/doc/:

for link in soup.find_all('a'):
    print(link.get('href'))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!