title: How to not take HTML scripts and only SQL scripts from a specific URL
body: <p>I am attempting to grab a bunch of SQL scripts sitting in a URL accessible via only a LAN, and then execute these SQL scripts with Python SQLite, but have realized that in that same request to grab the SQL, I also grab some HTML and this hinders my Python SQLite command from executing. Thus I cannot create the database.</p>
  
  <p>Here is the snippet of source code that does the request: </p>
  
  <pre><code>import requests
  
  builds_range = range(1300, 1351)
  print 'Getting data from the following URLs:'
  for build in builds_range:
    database_url = r'''http://192.168.1.253:8010/builders/Simulation/builds/{build_number}/steps/test%20trivial%20cases/logs/data'''.format(build_number = build)
    print database_url
    print requests.get(database_url).text
    import_db(db_script_url = database_url, submit_cur = db_cursor, 
              parameter_parser = lambda parameter : parameter_parser_final_iteration_with_constraint(parameter, None),
              build_number = build, extract_runtime = False)
  </code></pre>
  
  <p>And this is the snippet of code that actually does the execution of the SQL script to form the database:</p>
  
  <pre><code>import sqlite3
  
  def import_db(db_script_url, submit_cur, parameter_parser, build_number, extract_runtime) :
    conn = sqlite3.connect(':memory:')
    conn.executescript(requests.get(db_script_url).text)
    conn.commit()
  </code></pre>
  
  <p>Because of the fact that HTML gets in the way, you can see from my standard output with the help of <code>print requests.get(database_url).text</code> statement, that things look like:</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;&lt;title&gt;Log File contents&lt;/title&gt;
  &lt;link rel="stylesheet" href="../../../../../../../default.css" type="text/css" /&gt;
  &lt;/head&gt;
  &lt;body class='log'&gt;
  &lt;a href="data/text"&gt;(view as text)&lt;/a&gt;&lt;br/&gt;
  &lt;pre&gt;&lt;span class="stdout"&gt;
  BEGIN TRANSACTION;
  
  create table highlevelsynthesis(
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      name TEXT,
      parameter TEXT,
      rtl_output TEXT
  );
  </code></pre>
  
  <p>and further down the text in the URL, I also have problems with encoding in displaying the single quote characters:</p>
  
  <pre><code>INSERT INTO
  logfile(name, parameter, stdout, stderr, test_file, synthesis_config_file, status)
  VALUES (&amp;#39;dfmul&amp;#39;, &amp;#39;[[&amp;#34;scheduler_type&amp;#34;, &amp;#34;sdc&amp;#34;], [&amp;#34;max_chain_delay&amp;#34;, 0.9]]&amp;#39;, &amp;#39;/nfs/home/hongbin.zheng/buildslaves/253/Simulation/build/shang-build/tools/shang/testsuite/benchmark/legup_chstone/dfmul/20141210-103616-710585/hls.stdout&amp;#39;, &amp;#39;/nfs/home/hongbin.zheng/buildslaves/253/Simulation/build/shang-build/tools/shang/testsuite/benchmark/legup_chstone/dfmul/20141210-103616-710585/hls.stderr&amp;#39;, &amp;#39;/nfs/home/hongbin.zheng/buildslaves/253/Simulation/build/shang-build/tools/shang/testsuite/benchmark/legup_chstone/dfmul.bc&amp;#39;, &amp;#39;/nfs/home/hongbin.zheng/buildslaves/253/Simulation/build/shang-build/tools/shang/testsuite/benchmark/legup_chstone/dfmul/20141210-103616-710585/test_config.lua&amp;#39;, &amp;#39;passed&amp;#39;);
  </code></pre>
  
  <p>What should actually be in there in place of <code>&amp;#39;</code> is <code>'</code>.</p>
  
  <p>As a result of this HTML, when <code>conn.executescript(requests.get(db_script_url).text)</code>is executed, I get the following error: <code>OperationalError: near "&lt;": syntax error</code>. </p>
  
  <p>What really puzzles me is that whenever I repeat this with a URL like: <code>VIVADOJPEG500 = r'''http://192.168.1.253:8010/builders/LongTerm/builds/1261/steps/custom%20target/logs/data/text'''</code> that also contains a chunk of SQL, I totally do not have this issue. I initially thought it had something to do with the <code>r</code> in front of the string, but after testing my URL with it, I realized that adding an <code>r</code> does not solve the issue.</p>
  
  <p>Could someone who knows what is going on please help me to overcome this?</p>
  
  <p>Thank you very much.</p>