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


Groups > comp.lang.python > #99496

Re: Screen scraper to get all 'a title' elements

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Chris Angelico <rosuav@gmail.com>
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 <mailman.99.1448489447.20593.python-list@python.org> (permalink)
References <23ed6f4b-0ef2-4c9e-ade6-e597e7e03ca2@googlegroups.com> <a6f3a0a7-acc3-46db-a36b-c3d774293347@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de eyXsztocu8vYPU7tg3P/DgRICyy1CeIDr26ivRbCH/Aw==
Return-Path <rosuav@gmail.com>
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 <a6f3a0a7-acc3-46db-a36b-c3d774293347@googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
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>
Xref csiph.com comp.lang.python:99496

Show key headers only | View raw


On Thu, Nov 26, 2015 at 9:04 AM, ryguy7272 <ryanshuell@gmail.com> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Screen scraper to get all 'a title' elements ryguy7272 <ryanshuell@gmail.com> - 2015-11-25 12:42 -0800
  Re: Screen scraper to get all 'a title' elements MRAB <python@mrabarnett.plus.com> - 2015-11-25 20:55 +0000
    Re: Screen scraper to get all 'a title' elements Grobu <snailcoder@retrosite.invalid> - 2015-11-25 23:30 +0100
      Re: Screen scraper to get all 'a title' elements ryguy7272 <ryanshuell@gmail.com> - 2015-11-25 14:48 -0800
        Re: Screen scraper to get all 'a title' elements Chris Angelico <rosuav@gmail.com> - 2015-11-26 10:06 +1100
          Re: Screen scraper to get all 'a title' elements Grobu <snailcoder@retrosite.invalid> - 2015-11-26 00:44 +0100
            Re: Screen scraper to get all 'a title' elements Marko Rauhamaa <marko@pacujo.net> - 2015-11-26 01:53 +0200
              Re: Screen scraper to get all 'a title' elements Chris Angelico <rosuav@gmail.com> - 2015-11-26 10:59 +1100
            Re: Screen scraper to get all 'a title' elements Chris Angelico <rosuav@gmail.com> - 2015-11-26 10:54 +1100
            Re: Screen scraper to get all 'a title' elements Grobu <snailcoder@retrosite.invalid> - 2015-11-26 02:05 +0100
        Re: Screen scraper to get all 'a title' elements Grobu <snailcoder@retrosite.invalid> - 2015-11-26 00:33 +0100
          Re: Screen scraper to get all 'a title' elements ryguy7272 <ryanshuell@gmail.com> - 2015-11-25 15:37 -0800
            Re: Screen scraper to get all 'a title' elements Chris Angelico <rosuav@gmail.com> - 2015-11-26 10:42 +1100
  Re: Screen scraper to get all 'a title' elements ryguy7272 <ryanshuell@gmail.com> - 2015-11-25 14:04 -0800
    Re: Screen scraper to get all 'a title' elements Chris Angelico <rosuav@gmail.com> - 2015-11-26 09:10 +1100
  Re: Screen scraper to get all 'a title' elements TP <wingusr@gmail.com> - 2015-11-25 17:15 -0800
  Re: Screen scraper to get all 'a title' elements Denis McMahon <denismfmcmahon@gmail.com> - 2015-11-26 14:49 +0000

csiph-web