我试图从Investing.com提取特定日期的各种商品的价格表,使用Selenium和PhantomJS在R.Heres my PhantomJS脚本,用于提取白银价格。我不断收到错误,尤其是当我尝试添加点击按钮并设置日期的行时。有人有快速解决方法吗? (我试图绕过CasperJS)
var webPage = require('webpage');
var page = webPage.create();
var fs = require('fs');
var path = 'website.html'
page.open('https://www.investing.com/commodities/silver-historical-data', function (status) {
page.evaluate(function() {
document.getElementById("datePickerIconWrap").click();
document.getElementById("startDate").value = "09/01/2017";
document.getElementById("endDate").value = "11/01/2017";
document.getElementById("applyBtn").click();
});
var content = page.content;
fs.write(path,content,'w')
phantom.exit();
});
答案 0 :(得分:0)
不要点击
document.getElementById("datePickerIconWrap").click();
但请点击此处:
document.getElementById("widgetFieldDateRange").click();
然后设置值应该可以正常工作,就像这样
page.evaluate(function() {
document.getElementById("widgetFieldDateRange").click();
document.getElementById("startDate").value = "09/01/2017";
document.getElementById("endDate").value = "11/01/2017";
document.getElementById("applyBtn").click();
});