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


Groups > comp.lang.python > #5445

Trying to understand html.parser.HTMLParser

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <bahamutzero8825@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.015
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'parser': 0.05; 'snippet': 0.07; 'python': 0.07; '(right': 0.09; 'pages.': 0.09; 'this:': 0.11; 'def': 0.13; 'library': 0.15; "'a'": 0.16; 'fancy': 0.16; 'subject:Trying': 0.16; 'skip:m 30': 0.16; 'figure': 0.18; 'google,': 0.20; 'modules': 0.20; 'code': 0.22; '(and': 0.22; 'trying': 0.23; 'received:209.85.214.174': 0.23; 'received:mail- iw0-f174.google.com': 0.23; 'script': 0.26; "i'm": 0.26; "i'll": 0.26; 'external': 0.29; 'class': 0.29; 'message-id:@gmail.com': 0.30; 'import': 0.32; 'page.': 0.32; 'to:addr:python-list': 0.32; "i've": 0.33; 'relatively': 0.33; 'page': 0.33; 'module': 0.33; 'test': 0.33; "isn't": 0.34; 'received:192.168.1': 0.34; 'received:192': 0.34; 'skip:" 10': 0.34; 'header:User-Agent:1': 0.35; 'source,': 0.35; 'too': 0.36; 'none': 0.36; 'received:192.168': 0.37; 'some': 0.37; 'received:209.85': 0.37; 'either': 0.37; 'received:google.com': 0.38; 'but': 0.38; 'anything': 0.38; 'completely': 0.38; 'received:209.85.214': 0.39; 'returning': 0.39; 'to:addr:python.org': 0.39; 'received:209': 0.39; "it's": 0.40; 'header:Received:5': 0.40; 'simple': 0.60; 'url:nl': 0.60; 'skip:h 20': 0.60; 'back': 0.61; 'link': 0.62; 'tag,': 0.84; 'ultimately,': 0.84; 'url:dir': 0.84; 'page;': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:message-id:date:from:user-agent:mime-version:to :subject:x-enigmail-version:content-type:content-transfer-encoding; bh=+bUq+amVd7mYaERJfknsZJsb9tNJgrzcaJv5dJ41yDQ=; b=XWvO3lez/KJ8N9nDH3nouXdO8jKyODnGBoXxxbIgyd7aeIKPJJz+hMvKD6pChTuP8h Dq55A9C22EvlO28ecazdDLjUM/9pGsguOTXkhwsF5e8aKXe4c5/i2rDAuPfMQBHGjJef 1V83H0HxedgzfzTRFH3XZq8m+N83s9mzSrdkI=
DomainKey-Signature a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :x-enigmail-version:content-type:content-transfer-encoding; b=AjR+4NOYNUotp6yOsjteKPlg624htwuG3ogozsahC5h0lzU9kFJI2GQcTOP7+kGFJy rVdWK7DngHl3PbPYgTJd8kiA7zDfXJPLl5OCJXe9IX4Ld9fVn5ou9M7gu6FsXnoxipk3 rYaj5zFeC2lcMyXC8vHD1L4kF3lzdM9WMsPUo=
Date Sun, 15 May 2011 15:45:29 -0500
From Andrew Berg <bahamutzero8825@gmail.com>
User-Agent Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 ThunderBrowse/3.3.5
MIME-Version 1.0
To python-list@python.org
Subject Trying to understand html.parser.HTMLParser
X-Enigmail-Version 1.1.1
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1599.1305492338.9059.python-list@python.org> (permalink)
Lines 29
NNTP-Posting-Host 82.94.164.166
X-Trace 1305492338 news.xs4all.nl 41114 [::ffff:82.94.164.166]:53451
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:5445

Show key headers only | View raw


I'm trying to understand why HMTLParser.feed() isn't returning the whole
page. My test script is this:

import urllib.request
import html.parser
class MyHTMLParser(html.parser.HTMLParser):   
    def handle_starttag(self, tag, attrs):
        if tag == 'a' and attrs:
            print(tag,'-',attrs)

url = 'http://x264.nl/x264/?dir=./64bit/8bit_depth'
page = urllib.request.urlopen(url).read()
parser = MyHTMLParser()
parser.feed(str(page))

I can do print(page) and get the entire HTML source, but
parser.feed(str(page)) only spits out the information for the top links
and none of the "revisionxxxx" links. Ultimately, I just want to find
the name of the first "revisionxxxx" link (right now it's
"revision1995", when a new build is uploaded it will be "revision2000"
or whatever). I figure this is a relatively simple page; once I
understand all of this, I can move on to more complicated pages.

I've searched Google, but everything I find is either outdated, a
recommendation for some external module (I don't need to do anything too
fancy and most modules don't completely support Python 3 anyway) or is
just a code snippet with no real explanation. I had a book that
explained this, but I had to return it to the library (and I'll have to
get back in line to check it out again).

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


Thread

Trying to understand html.parser.HTMLParser Andrew Berg <bahamutzero8825@gmail.com> - 2011-05-15 15:45 -0500

csiph-web