BeautifulSoup的string是navigablestring,不能存入数据库咋办

https://www.crummy.com/software/BeautifulSoup/bs4/doc/#navigablestring话说错误日志都告诉你是因为传入的参数是个navigablestring了才出问题的情况下,你是如何得到type是unicode的结论的?
■网友
参照这个 The first option is the correct way to put query parameters into the query - it is called a parameterized query. In this case, you are letting the database driver to escape the query parameters, safely insert them into the query and handle the Python-to-MySQL type conversions.The error you are getting means that it could not convert one of the ID, Record, Latitude, Longitude or code parameter values to a valid MySQL database type. To be specific, see the variable types you have posted:ID \u0026lt;type \u0026#39;unicode\u0026#39;\u0026gt; Record \u0026lt;type \u0026#39;unicode\u0026#39;\u0026gt;Latitude \u0026lt;class \u0026#39;bs4.element.NavigableString\u0026#39;\u0026gt;Longitude \u0026lt;class \u0026#39;bs4.element.NavigableString\u0026#39;\u0026gt;code \u0026lt;type \u0026#39;unicode\u0026#39;\u0026gt;The problem is with Latitude and Longitude - they are BeautifulSoup\u0026#39;s NavigableString class instances - the MySQL converter having difficulties in understanding how to convert a NavigableString object into a valid MySQL type. Convert them to strings explicitly beforehand:update = """ INSERT INTO myDB.newtable (ID,Record,Latitude,Longitude,code) VALUES (%s,%s,%s,%s,%s)"""cursor2.execute(update, (ID, Record, str(Latitude), str(Longitude), code))


    推荐阅读