关于刮削部分,这是一个发送表单URL编码数据的POST请求。有效载荷中有两个字段似乎是必需的:
-
_ eventTarget=ctl00$b_中心$voturiplen1$calvot
-
_ EventArgument=XXXX(带XXXX某个值)
这个
__EVENTARGUMENT
值每天递增。例如,2018年4月4日是6668,2018年4月5日是6669。从最早的日期(1998年1月1日)来看,该指数为-730,因此可以使用目标日期和1998年1月1日之间的天数差减去730来计算该指数。
使用
curl
和;
bash
和
dateutils
:
target_date="2018-04-04"
index=$(($(dateutils.ddiff 1998-01-01 "$target_date") - 730))
curl 'https://www.senat.ro/Voturiplen.aspx' \
-H 'User-Agent: Mozilla' \
-H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
--data "__EVENTTARGET=ctl00%24B_Center%24VoturiPlen1%24calVOT&__EVENTARGUMENT=$index"
和使用
pup
HTML分析程序:
curl 'https://www.senat.ro/Voturiplen.aspx' \
-H 'User-Agent: Mozilla' \
-H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
--data "__EVENTTARGET=ctl00%24B_Center%24VoturiPlen1%24calVOT&__EVENTARGUMENT=$index" | \
pup 'table#ctl00_B_Center_VoturiPlen1_GridVoturi'
使用
nodejs
你可以用
node-request
,
moment
:
const request = require('request');
const moment = require('moment');
const jsdom = require("jsdom");
const {JSDOM} = jsdom;
var a = moment('21/12/2017', 'DD/MM/YYYY');
var b = moment('01/01/1998', 'DD/MM/YYYY');
var index = a.diff(b, 'days') - 730;
request.post({
url: 'https://www.senat.ro/Voturiplen.aspx',
form: {
"__EVENTTARGET": "ctl00$B_Center$VoturiPlen1$calVOT",
"__EVENTARGUMENT": index
},
headers: {
'User-Agent': 'Mozilla'
}
},
function(err, httpResponse, body) {
const dom = new JSDOM(body);
var table = dom.window.document.querySelector("#ctl00_B_Center_VoturiPlen1_GridVoturi");
console.log(table.textContent);
});
检查
this post
用于日期差异
瞬间