json - how to convert compiled url in normail form using python -
i used gogole api search via python , used script below
import urllib import json m_json query = raw_input ( 'query: ' ) query = urllib.urlencode ( { 'q' : query } ) response = urllib.urlopen ( 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&' + query ).read() json = m_json.loads ( response ) results = json [ 'responsedata' ] [ 'results' ] result in results: url = result['url'] # url in original , threw name error exception print ( url )
and after got result below :
query: inurl:"readnews.php?id=" http://www.idmantv.az/readnews.php%3fid%3d14999 http://www.kanda.com/readnews.php%3fid%3d9 http://www.dcfever.com/news/readnews.php%3fid%3d12573 http://www.thegrower.org/readnews.php%3fid%3d6c0p5n0e8i6b
but want url in normal form like
http://www.idmantv.az/readnews.php?id=14999
how python?
use urllib.unquote
or urllib.unquote_plus
decode %
-encoded string:
>>> urllib.unquote('http://www.idmantv.az/readnews.php%3fid%3d14999') 'http://www.idmantv.az/readnews.php?id=14999'
Comments
Post a Comment