Update YahooGrabber in ticker.py.
authorW. Trevor King <wking@drexel.edu>
Wed, 29 Feb 2012 22:31:08 +0000 (17:31 -0500)
committerW. Trevor King <wking@drexel.edu>
Wed, 29 Feb 2012 22:31:08 +0000 (17:31 -0500)
posts/ticker/ticker.py

index f96aadda7e2da677405af88ee6428ef823f527bb..471208976e1acccec4e1f17559fdacb2578bee9b 100755 (executable)
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-# Copyright (C) 2010  W. Trevor King <wking@drexel.edu>
+# Copyright (C) 2010-2012  W. Trevor King <wking@drexel.edu>
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -118,36 +118,17 @@ class YahooGrabber (Grabber):
     def _parse_html(self, html):
         """Extract quote from a snippet that looks like::
 
-            <tr>
-              <th ...>Last Trade:</th>
-              <td ...>
-                <big>
-                  <b>
-                    <span ...>
-                      64.74
-                    </span>
-                  </b>
-                </big>
-              </td>
-            </tr>
-
-        For the implementation, see the `LXML tutorial`_.
-
-        .. _LXML tutorial:
-          http://codespeak.net/lxml/tutorial.html#using-xpath-to-find-text
+          <span class="time_rtq_ticker">
+            <span>
+              67.62
+            </span>
+          </span>
         """
         parser = etree.HTMLParser()
         tree = etree.parse(StringIO(html), parser)
         root = tree.getroot()
-        rows = root.xpath('.//tr')  #[[td/text() = 'Last Trade:']")
-        for row in rows:
-            has_label = row.xpath(".//th/text() = 'Last Trade:'")
-            if has_label:
-                break
-        assert has_label, '\n---\n\n'.join([
-                etree.tostring(row,  pretty_print=True) for row in rows])
-        data = row.xpath('.//td')[0]
-        text = ''.join(data.itertext()).strip()
+        span = root.xpath(".//span[@class='time_rtq_ticker']")[0]
+        text = ''.join(span.itertext()).strip()
         return float(text)