|
|
@@ -9,6 +9,52 @@ use Facebook\WebDriver\Remote\DesiredCapabilities;
|
|
|
use Facebook\WebDriver\Chrome\ChromeOptions;
|
|
|
use Facebook\WebDriver\Firefox\FirefoxOptions;
|
|
|
|
|
|
+
|
|
|
+function getUrlData($url, $simple = true) {
|
|
|
+ if( $simple ){
|
|
|
+ return file_get_contents($url);
|
|
|
+ }
|
|
|
+ // 初始化 cURL 会话
|
|
|
+ $ch = curl_init($url);
|
|
|
+ // 设置 cURL 选项
|
|
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 禁用 SSL 证书验证(仅在必要时使用)
|
|
|
+ // 发送请求并获取响应
|
|
|
+ $response = curl_exec($ch);
|
|
|
+ // 检查请求是否成功
|
|
|
+ if ($response === FALSE) {
|
|
|
+ // 关闭 cURL 会话
|
|
|
+ curl_close($ch);
|
|
|
+ return ['error' => 'Error occurred: ' . curl_error($ch)];
|
|
|
+ }
|
|
|
+ // 关闭 cURL 会话
|
|
|
+ curl_close($ch);
|
|
|
+ // 检查解码是否成功
|
|
|
+ if (json_last_error() !== JSON_ERROR_NONE) {
|
|
|
+ return ['error' => 'Error decoding JSON: ' . json_last_error_msg()];
|
|
|
+ }
|
|
|
+ // 返回解码后的数据
|
|
|
+ return $response;
|
|
|
+}
|
|
|
+
|
|
|
+function getRandProxyInfo(){
|
|
|
+ $url = 'https://getproxy.bzpl.tech/get/';
|
|
|
+ $response = getUrlData($url);
|
|
|
+ if ($response) {
|
|
|
+ $ret = json_decode($response, true);
|
|
|
+ if ($ret && $ret['proxy']) {
|
|
|
+ return array(
|
|
|
+ 'proxyType' => 'manual',
|
|
|
+ 'httpProxy' => $ret['proxy'],
|
|
|
+ 'sslProxy' => $ret['proxy'],
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+}
|
|
|
+
|
|
|
$driverType = 'chrome';
|
|
|
$capabilities = null;
|
|
|
|
|
|
@@ -42,6 +88,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+$isRspCookie = false;
|
|
|
if (isset($postData['url'])) {
|
|
|
$webUrl = urldecode($postData['url']);
|
|
|
if (!preg_match('/^(http:\/\/|https:\/\/)/', $webUrl)) {
|
|
|
@@ -60,6 +107,25 @@ if (isset($postData['headers'])) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+$isUseProxy = false;
|
|
|
+$proxy = null;
|
|
|
+if (isset($postData['useProxy'])) {
|
|
|
+ $isUseProxy = $postData['useProxy'] == 1 ? true : false;
|
|
|
+ if(isset($postData['proxy'])){
|
|
|
+ $proxy = [
|
|
|
+ 'proxyType' => 'manual',
|
|
|
+ 'httpProxy' => $postData['proxy'],
|
|
|
+ 'sslProxy' => $postData['proxy'],
|
|
|
+ ];
|
|
|
+ }else{
|
|
|
+ $proxy = getRandProxyInfo();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+if (isset($postData['rspCookie'])) {
|
|
|
+ $isRspCookie = $postData['rspCookie'] == 1 ? true : false;
|
|
|
+}
|
|
|
+
|
|
|
// selenium-server-standalone-#.jar (version 4.x)
|
|
|
switch ($driverType) {
|
|
|
case 'chrome':
|
|
|
@@ -73,12 +139,14 @@ switch ($driverType) {
|
|
|
$userAgent = $customHeaders['User-Agent'];
|
|
|
}
|
|
|
$options->addArguments([
|
|
|
- // '--headless', // 启用无头模式
|
|
|
+ '--headless', // 启用无头模式
|
|
|
'--disable-gpu', // 禁用GPU加速
|
|
|
'--user-agent='.$userAgent,
|
|
|
'--disable-blink-features=AutomationControlled',
|
|
|
'--disable-browser-side-navigation',
|
|
|
- '--disable-dev-shm-usage'
|
|
|
+ '--no-sandbox',
|
|
|
+ '--disable-dev-shm-usage',
|
|
|
+ '--disable-extensions'
|
|
|
]);
|
|
|
$capabilities->setCapability(ChromeOptions::CAPABILITY, $options);
|
|
|
break;
|
|
|
@@ -98,6 +166,9 @@ switch ($driverType) {
|
|
|
|
|
|
// Disable accepting SSL certificates
|
|
|
$capabilities->setCapability('acceptSslCerts', false);
|
|
|
+if($proxy){
|
|
|
+ $capabilities->setCapability('proxy', $proxy);
|
|
|
+}
|
|
|
|
|
|
$driver = RemoteWebDriver::create($serverUrl, $capabilities);
|
|
|
|
|
|
@@ -127,9 +198,12 @@ if($customHeaders && isset($customHeaders['Cookie'])){
|
|
|
|
|
|
$content = $driver->getPageSource();
|
|
|
|
|
|
-$cookies = $driver->manage()->getCookies();
|
|
|
-
|
|
|
-echo $content;
|
|
|
+if($isRspCookie){
|
|
|
+ $cookies = $driver->manage()->getCookies();
|
|
|
+ echo json_encode(array('cookie' => $cookies, 'content' => $content));
|
|
|
+} else {
|
|
|
+ echo $content;
|
|
|
+}
|
|
|
|
|
|
$driver->quit();
|
|
|
?>
|