webbrowser fragment identifier

S

scottbvfx

Hi,

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
this.
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)?

Thanks,
-Scott
 
T

Tim Golden

scottbvfx said:
Hi,

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
this.
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.

TJG
 
G

Gabriel Genellina

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
this.
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)?

It's not Python which truncates the path - webbrowser.open doesn't modify
the url given.
Looks like you're on Windows. Internet Explorer exposes a COM interface
that you may use to control it. Google for "python IE automation"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,224
Latest member
BettieToom

Latest Threads

Top