United States Department of Agriculture 美国农业部网站数据自动下载小脚本

帮对象写的自动点击页面的小脚本,如果有需要的可以试试,(#^.^#)

https://apps.fas.usda.gov/gats/ExpressQuery1.aspx

 var year = '1991';

 var box3 = document.querySelector("#ctl00_ContentPlaceHolder1_lb_Partners");
box3.value='ALLRG';
box3 = document.querySelector("#ctl00_ContentPlaceHolder1_lb_Products");
box3.value='M1';
box3 = document.querySelector("#ctl00_ContentPlaceHolder1_ddlValueUnit");
box3.value='M';
box3 = document.querySelector("#ctl00_ContentPlaceHolder1_ddlDateSeries");
box3.value='Annual';
box3 = document.querySelector("#ctl00_ContentPlaceHolder1_ddlOrderBy");
box3.value='CODE';
box3 = document.querySelector("#ctl00_ContentPlaceHolder1_ddlInDetail");
box3.value='Product';
box3 = document.querySelector("#ctl00_ContentPlaceHolder1_ddlCalculation");
box3.value=''; box3 = document.querySelector("#ctl00_ContentPlaceHolder1_ddlStartYear");
box3.value= year;
box3.dispatchEvent(new Event('change'));
box3 = document.querySelector("#ctl00_ContentPlaceHolder1_ddlEndYear");
box3.value= year;
box3.dispatchEvent(new Event('change')); function clickStep()
{
if (document.querySelector("#overlay").style.display == 'block') {
setTimeout("clickStep()", 1000);
return;
}
console.log("触发点击事件")
document.querySelector("#ctl00_ContentPlaceHolder1_btnRetrieveData").click();
}
setTimeout("clickStep()", 1000); String.prototype.startWith=function(str){
var reg=new RegExp("^"+str);
return reg.test(this);
}
var clicked = false;
function doExpand() {
box3 = document.querySelector("#ctl00_ContentPlaceHolder1_UltraWebTab1__ctl1_grdExpressQuery_GridView1");
var rows = box3.rows;
var inputs = [];
for (var index in rows) {
var length = rows[index].cells ? rows[index].cells.length : 0;
if (length < 4) {
continue;
}
var nodes = rows[index].cells[3].childNodes;
if (nodes.length == 0) {
continue;
}
if (nodes[0].nodeName == '#text') {
continue;
}
var cell5Text = rows[index].cells[4].innerText;
if (!cell5Text.startWith('Bulk Total') && !cell5Text.startWith('Intermediate Total') && !cell5Text.startWith('Consumer Oriented Total')) {
continue;
} var input = nodes[0]; if(input.value == '-') {
continue;
} clicked = true;
input.click();
break;
}
} var index = 0;
function expandStep()
{
if (document.querySelector("#overlay").style.display == 'block' || document.querySelector("#ctl00_ContentPlaceHolder1_UltraWebTab1") == null) {
setTimeout("expandStep()", 1000);
return;
}
console.log((index++) + "打开,total:" );
doExpand();
if (!clicked) {
alert("展开完成,请下载")
return;
} else {
clicked = false;
}
expandStep();
} setTimeout("expandStep()", 5000);
上一篇:201521123049 《JAVA程序设计》 第6周学习总结


下一篇:Unity UGUI实现鼠标拖动图片