我想使用以下python代码在网页中获取值:
import requests
url = 'https://www2.usgs.gov/water/lowermississippigulf/lmgweb/meras/cell_log.html?longitude=-90&latitude=35&x_coordinate=542742.2705864373&y_coordinate=1343939.7318854574'
page = requests.get(url)
但是,page.content
没有显示任何数值。该页面似乎提供了图形输出,而不是表格输出的数值。您能帮我解决这个问题并在网页中获取表格吗?
答案 0 :(得分:0)
您将请求发送到错误的网址,请尝试以下代码:
import requests
url = "https://www2.usgs.gov:443/water/lowermississippigulf/cgi/meras/framework/framework_well_log.pl?longitude=-90&latitude=35&x_coordinate=542742.2705864373&y_coordinate=1343939.7318854574&rasters=tiffs/alvm_surf.tif%20tiffs/vkbg_surf.tif%20tiffs/ucaq_surf.tif%20tiffs/mccu_surf.tif%20tiffs/mcaq_surf.tif%20tiffs/lccu_surf.tif%20tiffs/lcaq_surf.tif%20tiffs/mwaq_surf.tif%20tiffs/lwaq_surf.tif%20tiffs/mdwy_surf.tif&color=framework_color_map.txt"
page = requests.get(url).json()
返回JSON字符串,这就是为什么我在末尾使用.json()
的原因(您可以随时将.json()
更改为.content
)