Guest User

Untitled

a guest
Feb 24th, 2012
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. #With BeautifulSoup
  2. items = [(x[0].text, x[0].get('href')) for x in
  3.         filter(None, [
  4.           x.findChildren() for x in
  5.             soup.findAll('td', {'class':'title'})
  6.         ])]
  7.  
  8.       for item in items:
  9.         print item
  10.         news_item = NewsItem()
  11.         news_item['title']  = item[0]
  12.         news_item['url']    = item[1]
  13.  
  14. # Without using BeautifulSoup.
  15. for item in hxs.select('//td[@class="title"]/a'):
  16.     news_item = NewsItem()
  17.     news_item['title'] = item.select('text()').extract()[0]
  18.     news_item['url'] = item.select('@href').extract()[0]
Advertisement
Add Comment
Please, Sign In to add comment