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?
ringa_lee2017-07-04 13:45:48
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
为情所困2017-07-04 13:45:48
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]