Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Screen scraper to get all 'a title' elements Date: Thu, 26 Nov 2015 10:54:04 +1100 Lines: 36 Message-ID: References: <23ed6f4b-0ef2-4c9e-ade6-e597e7e03ca2@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de hJ3TRLZnwaLoCaJ1ge+i9wyF+0EbzKJ6/bFane/I0ZKg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'broken': 0.03; 'received:209.85.223': 0.03; 'expressions': 0.07; "subject:' ": 0.07; 'cc:addr:python-list': 0.09; 'compact': 0.09; 'parsed': 0.09; ':-)': 0.12; 'thu,': 0.15; 'describing': 0.16; 'expressions,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'side.': 0.16; 'soup': 0.16; 'uses,': 0.16; 'wrote:': 0.16; 'language': 0.19; '>>>': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'parse': 0.22; 'parsing': 0.22; 'sorry,': 0.22; 'suppose': 0.22; 'trying': 0.22; 'am,': 0.23; 'seems': 0.23; 'header:In-Reply-To:1': 0.24; 'chris': 0.26; 'message-id:@mail.gmail.com': 0.27; 'regular': 0.29; 'doing?': 0.29; 'that.': 0.30; 'code': 0.30; 'mention': 0.30; 'programmers': 0.30; 'subject:all': 0.32; 'html,': 0.33; 'list': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'text': 0.35; 'nov': 0.35; 'but': 0.36; 'too': 0.36; 'there': 0.36; 'tool': 0.36; 'received:209.85': 0.36; "wasn't": 0.36; 'subject:: ': 0.37; 'being': 0.37; 'received:209': 0.38; 'stuff': 0.38; 'wrong': 0.38; 'end': 0.39; 'why': 0.39; 'does': 0.39; 'easily': 0.39; 'where': 0.40; 'some': 0.40; 'side': 0.62; 'more': 0.63; 'places': 0.64; 'beautiful': 0.66; "they're": 0.66; '26,': 0.72; 'subject:get': 0.81; 'chrisa': 0.84; 'dark': 0.84; 'ready-made': 0.84; 'wanted,': 0.84; 'to:none': 0.91; 'innocent': 0.91; 'good,': 0.93; 'reliable,': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=o7jbetgspFSaiP1VvebhLNgLO+R3DGDkzb8a6r7/pmA=; b=brMKCd5LDFfUZHh+Gr+SvI7mGiKt43EgnqnPukKXHdKHWLPu52bShusvtbI7ueU3YB 7qrAmMKZxGBLmTR0Q2PbHIX1RvEWCtKZ+MNMQ/oyUoZ/+8c5kyGAw/ZMkAH5hGeQXZuh CegBHZbJoDLnUExH0d7/oDhd/593MSJnOenfmToju/U5lwNgBkXqh84ZlwWKukWMNviQ ZMnBgzIPCq29LN2Px9zhp01qh5uuzfXfHObP7kxROMSHbnM8RDniA3Wujq9kVSSmT6nF duJhYotUahh/2r2uUISG9sADVrHSNuNLCwoMksVo2G4SXf8MGDCV8iSn4b2HOuxOi82Q Ee8Q== X-Received: by 10.107.16.84 with SMTP id y81mr35389077ioi.19.1448495644785; Wed, 25 Nov 2015 15:54:04 -0800 (PST) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:99510 On Thu, Nov 26, 2015 at 10:44 AM, Grobu wrote: > On 26/11/15 00:06, Chris Angelico wrote: >> >> On Thu, Nov 26, 2015 at 9:48 AM, ryguy7272 wrote: >>> >>> Thanks!! Is that regex? Can you explain exactly what it is doing? >>> Also, it seems to pick up a lot more than just the list I wanted, but >>> that's ok, I can see why it does that. >>> >>> Can you just please explain what it's doing??? >> >> >> It's a trap! >> >> Don't use a regex to parse HTML, unless you're deliberately trying to >> entice young and innocent programmers to the dark side. >> >> ChrisA >> > > Sorry, I wasn't aware of regex being on the dark side :-) > Now that you mention it, I suppose that their being complex and > error-inducing could lead to broken code all too easily when there is a > reliable, ready-made solution like BeautifulSoup. Regular expressions have their uses, but parsing HTML is not one of them. The most important use of a regex is letting an end user control the search pattern; it's a compact language for describing a variety of text search concepts. For hard-coded regular expressions, there are some places where they're very good, and a lot of places where they're the wrong tool for the job. And one of those wrong-tool-for-job places is parsing stuff that fundamentally cannot be parsed with regexes, such as HTML. You _need_ a proper parser, which is what Beautiful Soup is for. ChrisA