擅长:python、mysql、java
<p>正如@Piotrek所写,问题不在代码中。我想问题出在服务器端。这对我很有效:</p>
<ol>
<li>我使用了<strong>方法2</strong></li>
<li>在打开url链接之前,我已经打开了下面的“父”url
(<a href="https://mobec.sk/vrbovce#base" rel="nofollow noreferrer">https://mobec.sk/vrbovce#base</a>),它使用这些图像来
创建地图</li>
<li>在下一步中,我在<br/>中打开了图像的url链接
使用selenium python模块的chrome web浏览器</li>
<li>之后,我可以拍下照片的截图</li>
</ol>
<p>这是对我有用的代码:</p>
<pre><code>from selenium import webdriver
from PIL import Image
from io import BytesIO
web_driver = webdriver.Chrome('path/to/chromedriver')
web_driver.get('https://mobec.sk/vrbovce#base')
web_driver.get('https://mobec.sk/proxy/geo?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&layers=custom%3Avrbovce_elektrina&tiled=true&STYLES=&WIDTH=512&HEIGHT=512&CRS=EPSG%3A3857&FORMAT_OPTIONS=dpi%3A180&BBOX=1947003.9844800085%2C6242153.477880634%2C1949449.969385134%2C6244599.46278576')
png = web_driver.get_screenshot_as_png()
im = Image.open(BytesIO(png))
im.save('output.png')
web_driver.quit()
</code></pre>