beautiful soup get class info

teddybubu at gmail.com teddybubu at gmail.com
Fri Mar 7 02:37:28 CET 2014


On Thursday, March 6, 2014 4:28:06 PM UTC-6, John Gordon wrote:
> In <ae5b837c-501d-498e-bd3a-3b2c709c42b0 at googlegroups.com>  writes:
> 
> 
> 
> > > soup.find_all(name="span", class="date")
> 
> 
> 
> > I have python 2.7.2 and it does not like class in the code you provided.
> 
> 
> 
> Oh right, 'class' is a reserved word.  I imagine beautifulsoup has
> 
> a workaround for that.
> 
> 
> 
> > Now when I take out [ class="date"], this is returned:
> 
> >    [<span class="date">March 5, 2014</span>, <span class="date">March 5, 2014</span>]
> 
> >  
> 
> > This is the code I am using: "data = soup.find_all(name="span") 
> 
> > print (data)"
> 
> > 1. it returns today's date instead of the actual date
> 
> > 2. returns it twice
> 
> 
> 
> Are there two occurrences of '<span class="date">March 5, 2014</span>'
> 
> in the HTML?  If so, then beautifulsoup is doing its job correctly.
> 
> 
> 
> It might help if you posted the sample HTML data you're working with.
> 
> 
> 
> -- 
> 
> John Gordon         Imagine what it must be like for a real medical doctor to
> 
>    watch 'House', or a real serial killer to watch 'Dexter'.

ok I got this working. now to the next problem.... thanks.



More information about the Python-list mailing list