python problem of retrieving URLs from mysql database
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-07-04 13:43:48
0
2
1054

After fetching the link from the database, it prints out like this,

(u'https://www.baidu.com',)

The type of this field in the database is Varchar, this is the code

for row in results:
    print row

I printed it directly as https://www.baidu.com. What should I do?

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(2)
ringa_lee

You should be

select url from xx_table limit 1;

Then the database is taken out as a tuple, which is returned in the order of your select, so just print the first element directly

results = (u'https://www.baidu.com',)
print results[0] # python2
# print(results[0]) # python3
为情所困

The database field of VARCHAR type corresponds to the string in Python. Haven’t you already obtained it?
If you want to use it as a value, just write:

url = results[0]
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template