title: UnboundLocalError: local variable 'items' referenced before assignment
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/9061565/convert-list-to-string-to-insert-into-my-sql-in-one-row-in-python-scrapy">convert list to string to insert into my sql in one row in python scrapy</a>  </p>
  </blockquote>
  
  
  
  <p>I am trying to write the data extracted from HTML pages directly to a MySQL database. But the code, which used to work, no longer does. Can someone please help me out?</p>
  
  <pre><code>def parse(self, response):
      hxs = HtmlXPathSelector(response)
      sites = hxs.select('//ul/li')
      con = MySQLdb.connect(
          host="localhost",
          user="dreamriks",
          passwd="dreamriks",
          db="scraped_data"
      )
      cur = con.cursor()
      for site in sites:
          items = [site.select('//h2').extract()]
          item = [site.select('//h3').extract()]
          meta = [site.select('//meta').extract()]
      for index in range (len( items)):              #&lt;-- exception raises here
          str = items[index]
          cur.execute("""Insert into h2_meta(h2) Values(%s)""",(str))
      con.commit()
      con.close()
  </code></pre>
  
  <p>The code above gives the following error:</p>
  
  <pre><code>exceptions.UnboundLocalError: local variable 'items' referenced before assignment
  </code></pre>