使用语言为nodejs
操作selenium包时,发现网页总是一闪而过,后来发现时oauth2框架编写的;也就是网页点击后,会进行网页重定向,产生键值对;即访问:www.xxx.com;实际会重定向到www.xxx.com/#?key=value等等;
百度搜索基本上都是通过browser-proxy拦截获取network的数据流,然后读取留,截取实际的网页,在进行访问;实际在多次下载包后,仍然无法使用,纠结一周了;
目前实践的情况
1、下载browsermob-proxy-2.1.4成功,可以运行批处理,是单独的小黑窗CMD;可以运行,发现默认代理8080;下载chrome驱动也成功,也配置了全局变量;
2、使用selenium
let webdriver = require('selenium-webdriver');
let chrome = require('selenium-webdriver/chrome');
let proxy = require('selenium-webdriver/proxy');
let opts = new chrome.Options();
(async function example() {
opts.setProxy(proxy.manual({ http: '<localhost:8080>' }));
let base_url = "http://www.baidu.com"
let driver = new webdriver.Builder()
.forBrowser('chrome')
.setChromeOptions(opts)
.build();
try {
await driver.get(base_url);
let title1 = await driver.getTitle();
console.log(title1)
}
finally {
await driver.quit();
}
}());
总是报错:Invalid 'main' field in 'D:\Fluduo\codeplay\project\Y2021\node_modules\browsermob-proxy\package.json' of './browsermob.js'. Please either fix that or report it to the module author
(估计是版本被depressed?要么是方法被弃用,要么就是不是个函数,哎,折磨啊)
总是无法获取到 .har 文件,这个是第三步。求解答。