python - 使用python触发网站文件下载

标签 python csv python-2.7 urllib2

有一个炒股网站叫finviz 。您可以为其屏幕设置特定参数,然后右下角有一个按钮,可让您将结果导出为 .cvs 文件。

我想在 python 2.7 中创建一个脚本,用于下载并分析文件。我想我可以使用 urllib2 访问该网站,但如何触发导出,然后从结果文件中读取?使用标准 urllib2.urlopen(url).read(),返回整个站点的 html 文件,而不是我需要的导出。

最佳答案

事实证明,至少在本例中,导出按钮实际上是指向不同 URL 的链接。那么筛选器的网址可能是: http://finviz.com/screener.ashx?v=111&f=sh_price_u1 。 导出版本的网址为:http://finviz.com/export.ashx?v=111&f=sh_price_u1 。 第二个网址具有触发下载的功能,因此我需要而不是 urllib2.urlopen("http://finviz.com/screener.ashx?v=111&f=sh_price_u1 ").read() urllib2.urlopen("http://finviz.com/export.ashx?v=111&f=sh_price_u1 ").read()

关于python - 使用python触发网站文件下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18595043/

相关文章:

python - 用python在网站文章中搜索关键词

python - 无法获得 tiff 图像分辨率

python - 在 with 语句外使用 python 变量

python - 我还能如何排除此 cron 作业的故障?

ruby-on-rails - rake 数据库 :seed unable to read CSV

python - 我们如何等待消息文本在 selenium 中弹出

python - 大文件读取问题

c - 读取 .CSV 文件并将其存储在另一个文件中

python - 无法在 Mac 上安装 pip2.7

Python 2.7 Tkinter : How would I config the shape under the mouse with key press