Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #68262

Re: beautiful soup get class info

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'problem:': 0.07; '22,': 0.09; 'append': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'url:software': 0.09; 'argument.': 0.16; 'attrs:': 0.16; 'class:': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'soup': 0.16; 'subject:class': 0.16; 'alpha': 0.16; 'wrote:': 0.18; 'thanks.': 0.20; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'fine': 0.24; "haven't": 0.24; 'code:': 0.26; 'header:X-Complaints-To:1': 0.27; 'code': 0.31; 'workaround': 0.31; 'but': 0.35; 'there': 0.35; 'christopher': 0.36; 'date.': 0.36; 'in:': 0.36; 'two': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'march': 0.61; 'email addr:gmail.com': 0.63; 'worth': 0.66; 'here': 0.66; 'believe': 0.68; 'yes': 0.68; 'results': 0.69; 'subject:get': 0.81; "'class'": 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: beautiful soup get class info
Date Wed, 12 Mar 2014 08:36:40 +0100
Organization None
References <e73d29eb-17bb-472e-bdc4-c38ca904c60f@googlegroups.com> <lfofai$9oc$1@ger.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p57bdba0c.dip0.t-ipconnect.de
User-Agent KNode/4.11.5
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.8074.1394609816.18130.python-list@python.org> (permalink)
Lines 47
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1394609816 news.xs4all.nl 2911 [2001:888:2000:d::a6]:42332
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:68262

Show key headers only | View raw


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 | NextPrevious in thread | Find similar | Unroll thread


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