Skip to content

Instantly share code, notes, and snippets.

@netdesign
Created September 26, 2011 12:20
Show Gist options
  • Select an option

  • Save netdesign/1242105 to your computer and use it in GitHub Desktop.

Select an option

Save netdesign/1242105 to your computer and use it in GitHub Desktop.
Why This?
def dataExtractor(node):
XMLNS_D = '{http://purl.org/dc/elements/1.0/}'
elem = tr.fromstring(node)
title = elem.find(XMLNS_D + 'Title').text
if title is not None:
title = title
else:
title = "nnn"
descr = elem.find(XMLNS_D + 'Description').text
if descr is not None:
descr = descr
else:
descr = "nnn"
url = elem.attrib['about']
row = [url, title, descr]
return row
curs.executemany('INSERT INTO dmoz (url, title, descr) VALUES(?, ?, ?)', [dataExtractor(theChunk[i]) for i in theChunk])
Traceback (most recent call last):
File "/usr/lib/python2.6/multiprocessing/process.py", line 232, in _bootstrap
self.run()
File "/usr/lib/python2.6/multiprocessing/process.py", line 88, in run
self._target(*self._args, **self._kwargs)
File "xmlFasterParser.py", line 73, in xmlParser
curs.executemany('INSERT INTO dmoz (url, title, descr) VALUES(?, ?, ?)', [dataExtractor(theChunk[i]) for i in theChunk])
TypeError: list indices must be integers, not str
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment