Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
try/except
  • Loading branch information
leandrotoledo committed Mar 22, 2016
1 parent e6f4a69 commit 75c2820
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions scraper.py
Expand Up @@ -20,13 +20,16 @@
table_name='secoes')

for secao in scraperwiki.sql.select("* FROM secoes"):
html = scraperwiki.scrape(secao['href'])
root = lxml.html.fromstring(html)

for el in root.cssselect("div.listaDepartamentoWrapper li a"):
href = el.get('href')
subsecao = el.findall('span')[0].text

scraperwiki.sqlite.save(unique_keys=['subsecao', 'href'],
data={"subsecao": subsecao, "href": href},
table_name='subsecoes')
try:
html = scraperwiki.scrape(secao['href'])
root = lxml.html.fromstring(html)

for el in root.cssselect("div.listaDepartamentoWrapper li a"):
href = el.get('href')
subsecao = el.findall('span')[0].text

scraperwiki.sqlite.save(unique_keys=['subsecao', 'href'],
data={"subsecao": subsecao, "href": href},
table_name='subsecoes')
except ValueError:
pass

0 comments on commit 75c2820

Please sign in to comment.