Don't know what happened with this : "pymysql.err.ProgrammingError: (1064..."
<p>Here is my code:</p>

<pre><code>from urllib.request import urlopen
from bs4 import BeautifulSoup as bs
import re
import pymysql

resp = urlopen("https://en.wikipedia.org/wiki/Main_Page").read().decode("utf-8")

soup = bs(resp ,"html.parser")

listUrls = soup.findAll("a", href=re.compile("^/wiki/"))

for url in listUrls:

        if not re.search('\.(jpg|JPG)$', url['href']):

            conn = pymysql.connect(
                            host='127.0.0.1',
                            user='root',
                            password='',
                            db='wikiurl',
                            charset='utf8mb4'
                           )
            try:
                with conn.cursor() as cursor:

                     sql = "insert into 'wikiurl'('urlname','urlhref') VALUES (%s , %s)"
                     cursor.execute(sql,(url.get_text(), "https://en.wikipedia.org" + url["href"]))
                     conn.commit()

            finally: 
                     conn.close()
</code></pre>

<p>Error:</p>

<blockquote>
  <p>pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''wikiurl'('urlname','urlhref') VALUES ('Wikipedia' , '<a href="https://en.wikipedia.org/w" rel="nofollow">https://en.wikipedia.org/w</a>' at line 1")</p>
</blockquote>

<p>I think your sql syntax has some error,but it is not easy to debug it.</p>

<p>I recommend you use this method to print what the real sql string that is sent to mysql server.pymysql manual above:</p>

<p><code>mogrify(self, query, args=None)</code></p>

<p>'''Returns the exact string that is sent to the database by calling the
execute() method.
This method follows the extension to the DB API 2.0 followed by Psycopg.'''
eg:</p>

<p>you can use</p>

<p><code>print cursor.mogrify(sql,(url.get_text(), "https://en.wikipedia.org" + url["href"]))</code></p>

<p>good luck!</p>

python mysql