10-13-2008, 03:26 AM | #1 |
Junior Member
Posts: 8
Karma: 10
Join Date: Oct 2008
Device: PRS 505
|
Replacing Chars in URL
Hi All,
Not familiar with python at all I need to write regexp or some other way to replace : within the url. What I have are links like this /story/55571:83405 problem is that parser is taking last five digits as port number while it's actually query string parameter that site is using. I can not use just use straight replace as that would foul up the http:// bit. Trying to use this Code:
def print_version(self, url): return re.sub(r'(\d):(\d)','\1/\2',url) Any ideas... Thanks |
10-13-2008, 04:18 AM | #2 |
creator of calibre
Posts: 43,850
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Code:
url = ':'.join(url.split(':')[:-1]) |
10-13-2008, 04:41 AM | #3 |
Junior Member
Posts: 8
Karma: 10
Join Date: Oct 2008
Device: PRS 505
|
Thanks... I'm trying to replace : with / where would I insert that?
|
10-13-2008, 09:00 AM | #4 |
Reticulator of Tharn
Posts: 618
Karma: 400000
Join Date: Jan 2007
Location: EST
Device: Sony PRS-505
|
|
10-13-2008, 09:24 AM | #5 |
Junior Member
Posts: 8
Karma: 10
Join Date: Oct 2008
Device: PRS 505
|
Just in case anybody needs this sort of think in the future I end up doing just replace 2x
Code:
url = url.replace(':','/') url = url.replace('http/','http:') |
10-13-2008, 09:25 AM | #6 |
Junior Member
Posts: 8
Karma: 10
Join Date: Oct 2008
Device: PRS 505
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Classic How to: Nook with any font (incl. Czech/Slovak/Russian/Polish and other chars) | lamzor | Nook Developer's Corner | 4 | 08-26-2010 08:47 AM |
unable to process folder with spanish chars | jomaweb | Calibre | 6 | 02-04-2010 05:11 AM |
unicode chars in epubs after flashing | hakim | Sony Reader | 4 | 10-12-2009 08:33 AM |
URL for GutenText please | AlexBell | Workshop | 2 | 06-26-2009 01:18 AM |
Bug (?) related to polish (non-ascii) chars | parasit | Calibre | 8 | 05-30-2009 03:55 PM |