从URL下载数据 [英] Download data from URL

查看:73
本文介绍了从URL下载数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这与stackoverflow策略并不一致,因为我没有展示我所做的事情,但是由于我缺乏技术专长,我真的不知道如何开始这个问题。希望有人可以发布解决方案或至少将我指出正确的方向。

It does not really align with stackoverflow policy since I am not showing what I have done but I really have no clue how to even start on this question given my lack of technical expertise. Hope someone can post a solution or at least point me to the right direction.

我要从此网站下载所有数据:

I want to download all the data from this website:

http://aps.dac.gov.in/APY/Public_Report1.aspx

我需要下载所有数据,即所有季节*全年*所有州*所有作物。更长的(令人沮丧的!)方法是单击所有框,然后按下载。

I need to download all the data i.e. all season * all year * all states * all crops. The longer (frustrating!) way to approach is to just click all the boxes and press download.

但是,我想知道是否有人有任何编程解决方案来下载此数据。我最好在R中执行此操作,因为这是我理解的语言,但可以随时标记其他编程语言。

However, I was wondering if anyone has any programming solution to download this data. I would preferably want to do this in R because that's the language I understand but feel free to tag other programming languages.

推荐答案

以下是使用RSelenium实例化浏览器并指示其进行出价的解决方案。

Here's a solution using RSelenium to instance a browser and direct it to do your bidding.

library(RSelenium)
driver <- rsDriver()
remDr <- driver[["client"]]
remDr$navigate("http://aps.dac.gov.in/APY/Public_Report1.aspx") #navigate to your page

您基本上需要告诉浏览器选择要标记的每个按钮,使用SelectorGadget查找每个按钮的唯一ID,然后将它们逐个传递给webElem。然后使用webElem方法使页面执行操作。

You basically need to tell the browser to select each button you want to mark, using SelectorGadget to find the unique ID for each, then pass them one-by-one to webElem. Then use the webElem methods to make the page do things.

webElem <- remDr$findElement(using = 'id', value = "TreeViewSeasonn0CheckBox")
webElem$highlightElement() #quick flash as a check we're in the right box
webElem$clickElement() #performs the click
#now do the same for each other box

webElem <- remDr$findElement(using = 'id', value = "TreeView1n0CheckBox") 
webElem$highlightElement()
webElem$clickElement()

webElem <- remDr$findElement(using = 'id', value = "TreeView2n0CheckBox") 
webElem$highlightElement()
webElem$clickElement()

webElem <- remDr$findElement(using = 'id', value = "TreeViewYearn0CheckBox")
webElem$highlightElement()
webElem$clickElement()

现在选择所需的报表,然后单击下载按钮。假设它是Excel格式。

Now choose the report form you want and click the download button. Assuming it's Excel format here.

webElem <- remDr$findElement(using = 'id', value = "DdlFormat")
webElem$sendKeysToElement(list("Excel", key = "enter"))
webElem <- remDr$findElement(using = 'id', value = "Button1")
webElem$clickElement() #does the click

对于它的价值,该网站在尝试下载时超时对我来说所有数据。您的结果可能会有所不同。

For what it's worth, the site timed out on trying to download all the data for me. Your results may vary.

这篇关于从URL下载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆