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: 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: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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: >> >> October 22, 2011 >> >> 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(""" ... alpha ... beta""") Use attrs: >>> soup.find_all(attrs={"class": "one"}) [alpha] Append an underscore: >>> soup.find_all(class_="two") [beta]