Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #68262
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: beautiful soup get class info |
| Date | 2014-03-12 08:36 +0100 |
| Organization | None |
| References | <e73d29eb-17bb-472e-bdc4-c38ca904c60f@googlegroups.com> <lfofai$9oc$1@ger.gmane.org> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.8074.1394609816.18130.python-list@python.org> (permalink) |
Christopher Welborn wrote:
> On 03/06/2014 02:22 PM, teddybubu@gmail.com wrote:
>> I am using beautifulsoup to get the title and date of the website.
>> title is working fine but I am not able to pull the date. Here is the
>> code in the url:
>>
>> <span class="date">October 22, 2011</span>
>>
>> In Python, I am using the following code:
>> date1 = soup.span.text
>> data=soup.find_all(date="value")
>>
>> Results in:
>>
>> []
>> March 5, 2014
>>
>> What is the proper way to get this info?
>> Thanks.
>>
>
> I believe it's the 'attrs' argument.
> http://www.crummy.com/software/BeautifulSoup/bs4/doc/
>
> # Workaround the 'class' problem:
> data = soup.find_all(attrs={'class': 'date'})
>
> I haven't tested it, but it's worth looking into.
Yes there are two ways to filtr by class:
>>> soup = bs4.BeautifulSoup("""
... <span class="one">alpha</span>
... <span class="two">beta</span>""")
Use attrs:
>>> soup.find_all(attrs={"class": "one"})
[<span class="one">alpha</span>]
Append an underscore:
>>> soup.find_all(class_="two")
[<span class="two">beta</span>]
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
beautiful soup get class info teddybubu@gmail.com - 2014-03-06 12:22 -0800
Re: beautiful soup get class info John Gordon <gordon@panix.com> - 2014-03-06 20:58 +0000
Re: beautiful soup get class info teddybubu@gmail.com - 2014-03-06 13:38 -0800
Re: beautiful soup get class info John Gordon <gordon@panix.com> - 2014-03-06 22:28 +0000
Re: beautiful soup get class info teddybubu@gmail.com - 2014-03-06 17:37 -0800
Re: beautiful soup get class info Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-07 01:48 +0000
Re: beautiful soup get class info Christopher Welborn <cjwelborn@live.com> - 2014-03-11 21:04 -0500
Re: beautiful soup get class info Peter Otten <__peter__@web.de> - 2014-03-12 08:36 +0100
csiph-web