电脑重装后se自动化过不了瑞数了
各位大佬,公司电脑重装之后,遇到一个神奇的问题,用自动化过不了瑞数了,试了多个网站的瑞数,均会返回400,下面是一个测试的代码:```
public class PlaywrightUtil {
private static final Logger log = LoggerFactory.getLogger(PlaywrightUtil.class);
public static Map getBrowserInfo() {
Map browserInfo = new HashMap();
try {
//使用自定义ms-playwright
Map map = new HashMap<>();
Playwright playwright = Playwright.create();
BrowserType browserType = playwright.chromium();
//开启浏览器
Browser browser = browserType.launch(getOptionsByContext());
//开启BrowserContext
BrowserContext browserContext = browser.newContext(new Browser.NewContextOptions());
browserContext.setDefaultNavigationTimeout(90000);
browserContext.setDefaultTimeout(90000);
//封装map缓存
browserInfo.put("playwright", playwright);
browserInfo.put("browser", browser);
browserInfo.put("browserContext", browserContext);
browserInfo.put("openTime", System.currentTimeMillis());
} catch (Exception e) {
log.error("启动浏览器出错!", e);
}
return browserInfo;
}
/**
* 设置浏览器启动参数
*
* @return
*/
public static BrowserType.LaunchOptions getOptionsByContext() {
//设置基本的启动配置,这里选择了‘有头’模式启动
ArrayList<String> argList = new ArrayList<>();
BrowserType.LaunchOptions options = new BrowserType.LaunchOptions();
options.setHeadless(false);//无头模式
//浏览器启动参数优化项
argList.add("--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36");//请求头
argList.add("--no-sandbox");//沙盒
argList.add("--disable-setuid-sandbox");//uid沙盒
argList.add("--disable-gpu");//GPU硬件加速
argList.add("--disable-dev-shm-usage");
argList.add("--no-zygote");
argList.add("--enable-automation");
argList.add("--disable-blink-features=AutomationControlled");//禁用启用Blink运行时的功能访问被识别使用webDriver
options.setArgs(argList);
return options;
}
public static void main(String[] args) {
Map map = PlaywrightUtil.getBrowserInfo();
Playwright playwright = (Playwright) map.get("playwright");
Browser browser = (Browser) map.get("browser");
BrowserContext browserContext =(BrowserContext) map.get("browserContext");
Page page = browserContext.newPage();
page.addInitScript(PubConstant.STEALTH_JS);// stealth.min.js
//page.navigate("https://amr.sz.gov.cn/outer/entSelect/gs.html", new Page.NavigateOptions());
page.navigate("https://www.gsxt.gov.cn/index.html", new Page.NavigateOptions());
page.waitForSelector("#keyword", new Page.WaitForSelectorOptions().setTimeout(30000));
}
}
```java
在公司重装后的电脑上,死活过不了,丢自己家用电脑就可以,playwright用的1.46.0, 指纹用了stealth.min.js ,测试能过https://bot.sannysoft.com/ 这个机器人检测网站
playwright也用python试过,也不行,也试过se 和 puppeteer+ puppeteer-extra-plugin-stealth 均返回400 ,大概率是系统有什么奇怪的问题,佬们有什么思路吗 addInitScript 不行,用eval过了
页:
[1]