简体   繁体   中英

I'm trying to find a way for browsers to read my URLs parameters when i'm sending a local file address with Python (Windows 10)

I'm trying to open an HTML/CSS/JS file in a browser with python.

No problem here, i'm sending an URL and everything is okay but when I want to add parameters to my URL like this: file:///C:/Users/Me/Desktop/pageHTML.html?x=38

Every browser will open it like this: file:///C:/Users/Me/Desktop/pageHTML.html

I read that Windows was doing it for strange security issues

So I was wondering if someone had a solution in Python or maybe in JS to this problem?

Unfortunatly, I cannot read it with a local server, this has to be a local file.

OK I found a way, this post already answer the question in java,but i think that I can answer for the newby like me that have problems with translating a langage to another.

So here is the code:

import tempfile
import webbrowser

def createRedirectPage(url):
    return("<!DOCTYPE HTML>" +
            "<meta charset=\"UTF-8\">" +
            "<meta http-equiv=\"refresh\" content=\"1; url=" + url + "\">" +
            "<script>" +
            "window.location.href = \"" + url + "\"" +
            "</script>" +
            "<title>Page Redirection</title>" +
            "<!-- Note: don't tell people to `click` the link, just tell them that it is a link. -->" +
            "If you are not redirected automatically, follow the <a href='" + url + "'>link</a>")

def createRedirectTempFile(url):
    tmp=tempfile.NamedTemporaryFile(delete=False)
    path=tmp.name+'.html'

    f=open(path, 'w')
    f.write(createRedirectPage(url))
    f.close()
    webbrowser.open('file://' + path)

createRedirectPage("YourURL")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM