title: How to extract all the source code under <table> and export as html?
body: <p>I am beginner of Scrapy. My goal is to <strong>extract selected tables from a big HTML page and then export the selected tables together in HTML format</strong>. So essentially, what I want is to <strong>get a shorter version of the original web page keeping only the <code>&lt;table&gt;</code> sections</strong>.</p>
  
  <p>The structure of each <code>&lt;table&gt;</code> section looks like this:</p>
  
  <pre><code>&lt;table&gt;
     &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt; 
            &lt;font&gt;
  </code></pre>
  
  <p>Currently, I am trying the following spider code but the <strong>problem</strong> is:</p>
  
  <ol>
  <li>it doesn't retain all the source formatting;</li>
  <li>the <code>&lt;table&gt;</code> and <code>&lt;/table&gt;</code> are not included;</li>
  <li>I don't know how to save the scraped results in html format.</li>
  </ol>
  
  <hr>
  
  <pre><code>  def parse(self, response):
        hxs = HtmlXPathSelector(response)
        titles = hxs.select("//document/type/sequence/filename/description/text/table")
        items = []
        for titles in titles:
            item = MyHtmlItem()
            item ["htmltext"] = titles.select("node()").extract()
            if (item["htmltext"]):
                items.append(item)
        return items
  </code></pre>
  
  <p>Can anyone give me some advice?</p>