parsing - Python: How to turn two for-statements into one? -
i'm trying parse web table , export data csv file.
i'm ignorant forming 2 xpaths followed single for-statement (or maybe 2 correct?).
current spider:
class myspider(basespider): symbols = ["scmp"] name = "dozen" allowed_domains = ["yahoo.com"] start_urls = ["http://finance.yahoo.com/q/is?s=scmp&annual"] def parse(self, response): hxs = htmlxpathselector(response) revenue = response.xpath('//td[@align="right"]/strong/text()') date = response.xpath('//tr[@class="yfnc_modtitle1"]/th/text()') items = [] rev in revenue: item = dozenitem() item["revenue"] = rev.re('\d*,\d*') items.append(item) return items[:3] days = [] day in dates: item = dozenitem() item["date"] = day.re('\d*') days.append(item) return items[:3]
i know needs work, i'm not sure direction go...?
this output:
as visible, can't dates fill in.
here html i'm parsing dates from:
<tr class="yfnc_modtitle1" style="border-top:none;"> <th scope="col" style="border-top:2px solid #000;text-align:right; font-weight:bold">dec 31, 2014</th> <th scope="col" style="border-top:2px solid #000;text-align:right; font-weight:bold">dec 31, 2013</th> <th scope="col" style="border-top:2px solid #000;text-align:right; font-weight:bold">dec 31, 2012</th> </tr> <tr> <td colspan="2">
for rev, day in zip(revenue, dates): pass # code here
Comments
Post a Comment