Python webbrowser不能与GIS一起工作

2024-09-28 23:20:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图写一个代码,将下载所有的数据从一个服务器,其中持有的.rar文件有关虚构的尸体粒子的学生项目。我现在得到的是对服务器的查询,它只需要输入特定数量的粒子,并以url的形式访问它来下载.rar文件

url = 'http://www.pg.geof.unizg.hr/geoserver/wfs?request=getfeature&version=1.0.0&service=wfs&&propertyname=broj,naziv_ko,kc_geom&outputformat=SHAPE-ZIP&typename=gf:katastarska_cestica&filter=<Filter+xmlns="http://www.opengis.net/ogc"><And><PropertyIsEqualTo><PropertyName>broj</PropertyName><Literal>1900/1</Literal></PropertyIsEqualTo><PropertyIsEqualTo><PropertyName>naziv_ko</PropertyName><Literal>Suma Striborova Stara (9997)</Literal></PropertyIsEqualTo></And></Filter>'

这是我想用web浏览器模块为粒子“1900/1”打开的“url”,但这样会出现错误:

This XML file does not appear to have any style information associated with it. The document tree is shown below.

当我手动输入这个网址下载文件没有问题。 我可以用什么方法使这个pythonweb应用程序工作? 我使用了一个webbrowser.open_new(url)选项,但它不起作用


Tags: 文件服务器httpurlwww粒子filterko
1条回答
网友
1楼 · 发布于 2024-09-28 23:20:38

你用错工具了webbrowser用于控制本机web浏览器。如果您只想下载一个文件,请使用^{}模块(如果无法安装请求,请使用^{}

import requests

r = requests.get('http://www.pg.geof.unizg.hr/geoserver/wfs', params={
    'request': 'getfeature',
    ...
    'filter': '<Filter xmlns=...>'
})
print(r.content) # or write it to a file, or whatever

注意requests将为您处理编码GET参数,您不必担心自己会转义请求

相关问题 更多 >