How to replace the windows url in web url to web url and need too download pdf files in python
Question:
Hi engineers & developers,
I am really worried and stuck in the python program to replace the windows based URL to a web URL. Unfortunately, I couldn’t find any solution for this. I do tried for hours to solve this problem but I couldn’t. if any one help me is a great service guys. Ok let me tell the problem below.
This is the URL
http://203.215.33.115/CompanyVerification/Pages/ViewPDF.aspx?reportFile=C:WindowsTEMP243dbd82-9e93-42bb-a5ec-8fa032e93fdf.pdf
when I basically run the python below code
url = """http://203.215.33.115/CompanyVerification/Pages/ViewPDF.aspx?reportFile=C:WindowsTEMP243dbd82-9e93-42bb-a5ec-8fa032e93fdf.pdf"""
print(url)
The output will be like this
http://203.215.33.115/CompanyVerification/Pages/ViewPDF.aspx?reportFile=C:WindowsTEMP£dbd82-9e93-42bb-a5ec-8fa032e93fdf.pdf
please check it has replaced some values from the original URL. In this parameter reportFile=
I want the URL to be replaced like this
http://203.215.33.115/CompanyVerification/Pages/ViewPDF.aspx?reportFile=C:/Windows/TEMP/243dbd82-9e93-42bb-a5ec-8fa032e93fdf.pdf
I tried and I failed
I wanted a common routine for downloading purpose of any file using URL in the python snippet. Because I am new to python. Please help me. Thanks in advance
Answers:
The reason this is happening is python is automatically interpreting the backslash followed by numbers as an escape sequence. The solution is to make the string a raw string by adding the r
prefix and replacing the
with /
.
url = r"""http://203.215.33.115/CompanyVerification/Pages/ViewPDF.aspx?reportFile=C:WindowsTEMP243dbd82-9e93-42bb-a5ec-8fa032e93fdf.pdf""".replace('\', '/')
print(url)
will output:
http://203.215.33.115/CompanyVerification/Pages/ViewPDF.aspx?reportFile=C:/Windows/TEMP/243dbd82-9e93-42bb-a5ec-8fa032e93fdf.pdf
Hi engineers & developers,
I am really worried and stuck in the python program to replace the windows based URL to a web URL. Unfortunately, I couldn’t find any solution for this. I do tried for hours to solve this problem but I couldn’t. if any one help me is a great service guys. Ok let me tell the problem below.
This is the URL
http://203.215.33.115/CompanyVerification/Pages/ViewPDF.aspx?reportFile=C:WindowsTEMP243dbd82-9e93-42bb-a5ec-8fa032e93fdf.pdf
when I basically run the python below code
url = """http://203.215.33.115/CompanyVerification/Pages/ViewPDF.aspx?reportFile=C:WindowsTEMP243dbd82-9e93-42bb-a5ec-8fa032e93fdf.pdf"""
print(url)
The output will be like this
http://203.215.33.115/CompanyVerification/Pages/ViewPDF.aspx?reportFile=C:WindowsTEMP£dbd82-9e93-42bb-a5ec-8fa032e93fdf.pdf
please check it has replaced some values from the original URL. In this parameter reportFile=
I want the URL to be replaced like this
http://203.215.33.115/CompanyVerification/Pages/ViewPDF.aspx?reportFile=C:/Windows/TEMP/243dbd82-9e93-42bb-a5ec-8fa032e93fdf.pdf
I tried and I failed
I wanted a common routine for downloading purpose of any file using URL in the python snippet. Because I am new to python. Please help me. Thanks in advance
The reason this is happening is python is automatically interpreting the backslash followed by numbers as an escape sequence. The solution is to make the string a raw string by adding the r
prefix and replacing the with
/
.
url = r"""http://203.215.33.115/CompanyVerification/Pages/ViewPDF.aspx?reportFile=C:WindowsTEMP243dbd82-9e93-42bb-a5ec-8fa032e93fdf.pdf""".replace('\', '/')
print(url)
will output:
http://203.215.33.115/CompanyVerification/Pages/ViewPDF.aspx?reportFile=C:/Windows/TEMP/243dbd82-9e93-42bb-a5ec-8fa032e93fdf.pdf