Saturday, 18 August 2018

qgis - Inserting %20 instead of a space as a string



I have 600 records that I need to be linked on a website. As clickable urls. But when I have the URL's, they only link to the 1st set of text before a space. So is there a code in QGIS that I can put in to alleviate this. I have tried: replace( "url"," ") with "%20" But this requires some more work.



Answer



There's more than just space that is not "URL safe".


If you are looking to URL encode your strings, try (for Python 2):


import urllib
url = urllib.urlencode(url)

This will handle spaces and a whole lot more.


This post has a quick table of the different characters you need to encode.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...