【发布时间】:2019-08-19 16:24:55
【问题描述】:
所以我有一个脚本可以从某些网站上读取表格。
当我在 Python IDE 中运行此脚本时,它运行良好。如果我尝试将它作为批处理文件独立运行,它就不起作用。它反映了以下错误: urllib.error.URLError:
关于什么可能导致它的任何想法?我的脚本很短:
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 18 20:24:04 2019
@author: blueb
"""
import requests
import numpy as np
import pandas as pd
dfs = pd.read_html("https://www.nea.gov.sg/dengue-zika/dengue/dengue-clusters")
count = 0
for df in dfs:
count += 1
print(df.head())
clusters_info = dfs[1]
clusters_info.to_csv('clusters.csv')
dls = "https://www.moh.gov.sg/docs/librariesprovider5/diseases-updates/weekly-infectious-bulletin_caseswk32y2019.xlsx?sfvrsn=cceaba67_0"
resp = requests.get(dls)
output = open('denguetrends.xlsx', 'wb')
output.write(resp.content)
output.close()
trends = pd.read_excel('denguetrends.xlsx')
trends.to_csv('denguetrends.csv')
【问题讨论】: