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 09:10:43 +1100 Lines: 17 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 eyXsztocu8vYPU7tg3P/DgRICyy1CeIDr26ivRbCH/Aw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'received:209.85.223': 0.03; "subject:' ": 0.07; 'cc:addr:python-list': 0.09; 'restriction': 0.09; 'titles,': 0.09; 'argument': 0.15; 'thu,': 0.15; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'set,': 0.16; 'soup': 0.16; 'wrote:': 0.16; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'am,': 0.23; 'this:': 0.23; 'second': 0.24; 'tried': 0.24; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'requests': 0.25; 'script': 0.25; 'message-id:@mail.gmail.com': 0.27; 'url:wikipedia': 0.29; 'print': 0.30; 'url:wiki': 0.30; 'skip:[ 10': 0.31; 'guess': 0.31; 'supposed': 0.31; 'subject:all': 0.32; 'useful': 0.33; 'received:google.com': 0.35; 'so,': 0.35; 'nov': 0.35; 'url:org': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'received:209': 0.38; 'url:en': 0.39; 'some': 0.40; '26,': 0.72; 'subject:get': 0.81; 'chrisa': 0.84; 'dict,': 0.84; 'to:none': 0.91 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=4+OXAjIchfXd4RdvgHQoGjc2Gs7qX2FS+lM06XLbp7E=; b=FvE5e+jh3kl6udQDgku6v5glV2vlCUrB8NzhHlijADB5L8YJFyPEA4UZtU6orDUXoD nc+049c9R+fk2l6yOv/AD9STaj8jqziI08VhEw9o8VQ56BxC65gs0KgrnKvBr6njjL0V i739ZOfMaSU4qNcPhQ2ZlskeERtP67cpfiXol/6kAa/x5AEwuFZJIha7/7iNa3mFHDge o9sF38/UtbLpiFvq1l+sNcWtXgfdL7ONDVTcmlr1ZQJIr9iiyE81V2thaTkXReeMPFmc lDf2pwGk+CoV8tb3gqTfDrrn7rUzuAg3xjNsxU/jSz2GTuKT5OdfQd8P64UwU6Ka8rnd qbBQ== X-Received: by 10.107.10.233 with SMTP id 102mr37084126iok.31.1448489443709; Wed, 25 Nov 2015 14:10:43 -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:99496 On Thu, Nov 26, 2015 at 9:04 AM, ryguy7272 wrote: > Ok, I guess that makes sense. So, I just tried the script below, and got nothing... > > import requests > from bs4 import BeautifulSoup > > r = requests.get("https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names") > soup = BeautifulSoup(r.content) > print soup.find_all("a",{"title"}) The second argument to find_all is supposed to be a dict, not a set, and it's only useful if you want to put some restriction on the titles. To simply enumerate all the titles, try this: [a.get("title") for a in soup.find_all("a")] ChrisA