"When I retrieve HTML from the URL, ""Page could not be displayed"" is returned."

Asked 1 years ago, Updated 1 years ago, 35 views

I have a question about python.I tried to get the source of the page in urllib.request.urlopen().read(), but I couldn't get it as I wanted.Details are as follows:The following program retrieved the specified url source and output it to "1.txt".

import urlib.request

url="http://www.data.jma.go.jp/obd/stats/etrn/view/10min_a1.php?
prec_no=91&block_no=47945&year=2016&month=8&day=22&view="
html_nodecoded=urllib.request.urlopen(url).read()
html_decoded=html_nodecoded.decode('utf-8')

filename = "1.txt"
fa=open(filename, "w", encoding="utf-8")
fa.write(html_decoded)
fa.close()

However, there was a problem here.
When I compared the page source with "1.txt" to make sure that the html was obtained correctly, I found that some of them were different and that the html was not obtained correctly.
Below is an excerpt of the neighborhood of 1.txt that was not accurately retrieved.

"1.txt"

........
  ...(omitted)..
  ..........
  <li>Value every 10 minutes</li>
  </ul></div>
<!--//pankuzu menu-->

<divid="main">
<!--contents-->
<h1class="print"> Value every 10 minutes</h1>

The <br/> page could not be displayed.<br/> Click the Back button in your browser
Please click.</div></div><div><div="footer_area"><div="nfooter">
<p> Meteorological Agency: 電話100-8122 Representative telephone: 03-3212-8341</p>ul>
<li><a href="http://www.jma.go.jp/jma/kishou/info/coment.html"> Meteorological Agency Home Page
About </a></li></ul>>>>>>>>>>>>>>>>>>>>>>>>

When I checked the source of the page, I found that some of the source code was
The <br/> page could not be displayed.<br/>Click the Back button in your browser.</div>
It turns out that it has been replaced with .

The URL of the destination page is as follows.
http://www.data.jma.go.jp/obd/stats/etrn/view/10min_a1.php?prec_no=91&block_no=47945&year=2016&month=8&day=22&view=

I'm at a loss as to how to get it exactly.

The execution environment is a command prompt for python 3.7, windows 10.

javascript python html python3

2022-09-30 14:37

1 Answers

Please check the URL you are getting again.
I've seen it, but it's just that HTTP requests don't exist.
For example, I got the following correctly.

"http://www.data.jma.go.jp/obd/stats/etrn/view/10min_a1.php?prec_no=44&block_no=1133&year=2016&month=8&day=22&view="


2022-09-30 14:37

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.