-
Notifications
You must be signed in to change notification settings - Fork 1
/
step1.js
70 lines (57 loc) · 2.33 KB
/
step1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//const moment = require('moment');
const request = require('request');
const cheerio = require('cheerio'); // 分析爬回來資料的dom點 jquery
const fs = require('mz/fs');
const chromedriver = require('chromedriver');
const webdriver = require('selenium-webdriver'),
By = webdriver.By,
until = webdriver.until;
//var fs = require('mz/fs');
var driver = new webdriver.Builder()
.forBrowser('chrome')
.build();
var result = [];
let url = 'https://www.fetc.net.tw/UX/UX0000Common/UX000007ContactUs';
driver.get(url);
driver.sleep(8000);
var result = [];
result[0] = driver.getPageSource().then(function (body) {
let $ = cheerio.load(body);
//取圖片
//fs.writeFile('step1.html', body, function (err) { console.log(err); });
// let tel = $('div.info .tel').text();
// tel = tel.replace(/[\s|\\n]+/g, '');
return body;
});
Promise.all(result).then(async (body) => {
//更新
fs.writeFile('step2.html', body, function (err) { console.log(err); });
console.log('step2');
//replace src="官方網的網址"
// replace form action =遠通
// setInterval(function () {
// console.log('打完的資料')
// driver.get('http://127.0.0.1:8080/step2.html');
// }, 5000)
//});
var stdin = process.openStdin();
stdin.addListener("data", function (d) {
// note: d is an object, and when converted to a string it will
// end with a linefeed. so we (rather crudely) account for that
// with toString() and then trim()
// console.log("you entered: [" +
// d.toString().trim() + "]");
let x = d.toString().trim();
driver.executeScript("document.getElementById('name').setAttribute('value','hello world')");
driver.executeScript("document.getElementById('mobileNo').setAttribute('value','0900000000')");
driver.executeScript("document.getElementById('email').setAttribute('value','[email protected]')");
driver.executeScript("document.getElementById('category').setAttribute('value','3')");
//driver.executeScript("document.getElementById('content').sendKeys() = 'test'");
driver.findElement(By.id('content')).sendKeys('xxxxx')
driver.executeScript(`document.getElementById('visualCaptcha-img-3').click()`);
});
/// console.log(ans);
//雨傘
//driver.input('xx')
}
)