baskar_p
baskar_p

Reputation: 665

Problem parsing with beautifulsoup

I'm trying to parse the following web page link. Code below:

import urllib2
import sys
from BeautifulSoup import BeautifulSoup

url = 'http://www.etsy.com/teams/list'
source = urllib2.urlopen(url)

soup = BeautifulSoup(source)
print soup.prettify()

print len(soup('h3')) #to print the no of occurances of h3 
h3s = soup.findAll('h3') #finding the same as above
print len(h3s)

The problem is, it prints 1. while the web page contains atleast 10 'h3'.I couldn't figure out where the problem lies I am using python 2.7 and BeautifulSoup 3.0.7

Upvotes: 1

Views: 326

Answers (1)

Zach Kelling
Zach Kelling

Reputation: 53819

I'd recommend using lxml instead:

>>> import lxml.html
>>> doc = lxml.html.parse('http://www.etsy.com/teams/list')
>>> len(doc.xpath('//h3'))
<<< 10

Upvotes: 2

Related Questions