webbrowser fragment identifier
mail at timgolden.me.uk
Fri Sep 19 12:05:43 CEST 2008
> I'm trying to launch a web browser along with an html file with a
> fragment identifier in its path. I'm using the webbrowser module for
> ie. webbrowser.open('file:///C:/myfile.html#SomeEntryInTheHTML')
> for some reason it is truncating the path to 'file:///C:/myfile.html'.
> Does anyone know a way of getting the fragment identifier in there
> (with webbrowser module or any other)?
No expertise here: just poking around. This seems to be
a slight peculiarity of browser and os cooperation. As
a comparison, try running os.startfile ("file://....#..")
or just pasting it into the command line. I don't understand
why this should be but it seems to lose it there as well.
Randomly tested on my XP box with Firefox 3 & IE 7:
Input: Start > Run > firefox c:\temp\t.html#chapter-i
Result: URL is escaped so ff3 starts with non-existent file:///c:/temp/t.html%23chapter-i
Input: Start > Run > file:///c:\temp\t.html#chapter-i (with ff3 as default)
Result: URL fragment is stripped so ff3 starts with file:///C:/temp/t.html
Input: Start > Run iexplore c:\temp\t.html#chapter-i
Result: Gets it right: ie7 starts with file:///C:/temp/t.html#chapter-i
Input: Start > Run > file:///c:\temp\t.html#chapter-i (with ie7 as default)
Result: URL fragment is stripped so IE7 starts with file:///C:/temp/t.html
A very quick perusal of the webbrowser source suggests it does nothing
more sophisticated than finding possible browsers, starting with firefox,
and stopping when it finds it. It then uses that as the command-line prefix
to whatever url is passed. So no stripping of url fragments happening there.
More information about the Python-list