|
21 | 21 | use Facebook\WebDriver\Remote\RemoteWebDriver; |
22 | 22 | use Facebook\WebDriver\Firefox\FirefoxOptions; |
23 | 23 | use Facebook\WebDriver\Firefox\FirefoxProfile; |
| 24 | +use Facebook\WebDriver\Chrome\ChromeOptions; |
24 | 25 |
|
25 | 26 | class URLAnalyzer |
26 | 27 | { |
@@ -134,7 +135,7 @@ public function analyze($url) |
134 | 135 | $domainRules = $this->getDomainRules($host); |
135 | 136 | if (isset($domainRules['useSelenium']) && $domainRules['useSelenium'] === true) { |
136 | 137 | try { |
137 | | - $content = $this->fetchFromSelenium($cleanUrl); |
| 138 | + $content = $this->fetchFromSelenium($cleanUrl, isset($domainRules['browser']) ? $domainRules['browser'] : 'firefox'); |
138 | 139 | if (!empty($content)) { |
139 | 140 | $processedContent = $this->processContent($content, $host, $cleanUrl); |
140 | 141 | $this->cache->set($cleanUrl, $processedContent); |
@@ -177,26 +178,42 @@ public function analyze($url) |
177 | 178 | * Tenta obter o conteúdo da URL usando Selenium |
178 | 179 | * |
179 | 180 | * @param string $url URL para buscar |
| 181 | + * @param array $domainRules Regras específicas do domínio |
180 | 182 | * @return string|null Conteúdo HTML da página |
181 | 183 | * @throws Exception Em caso de erro na requisição |
182 | 184 | */ |
183 | | - private function fetchFromSelenium($url) |
| 185 | + private function fetchFromSelenium($url, $browser) |
184 | 186 | { |
185 | 187 | $host = 'http://'.SELENIUM_HOST.'/wd/hub'; |
186 | 188 |
|
187 | | - $profile = new FirefoxProfile(); |
188 | | - $profile->setPreference("permissions.default.image", 2); // Não carrega imagens |
189 | | - $profile->setPreference("javascript.enabled", true); // Mantem habilitado javascripts |
190 | | - $profile->setPreference("network.http.referer.defaultPolicy", 0); // Sempre envia referer |
191 | | - $profile->setPreference("network.http.referer.defaultReferer", "https://www.google.com.br"); // Define referer padrão |
192 | | - $profile->setPreference("network.http.referer.spoofSource", true); // Permite spoofing do referer |
193 | | - $profile->setPreference("network.http.referer.trimmingPolicy", 0); // Não corta o referer |
| 189 | + if ($browser === 'chrome') { |
| 190 | + $options = new ChromeOptions(); |
| 191 | + $options->addArguments([ |
| 192 | + '--headless', |
| 193 | + '--disable-gpu', |
| 194 | + '--no-sandbox', |
| 195 | + '--disable-dev-shm-usage', |
| 196 | + '--disable-images', |
| 197 | + '--blink-settings=imagesEnabled=false' |
| 198 | + ]); |
| 199 | + |
| 200 | + $capabilities = DesiredCapabilities::chrome(); |
| 201 | + $capabilities->setCapability(ChromeOptions::CAPABILITY, $options); |
| 202 | + } else { |
| 203 | + $profile = new FirefoxProfile(); |
| 204 | + $profile->setPreference("permissions.default.image", 2); // Não carrega imagens |
| 205 | + $profile->setPreference("javascript.enabled", true); // Mantem habilitado javascripts |
| 206 | + $profile->setPreference("network.http.referer.defaultPolicy", 0); // Sempre envia referer |
| 207 | + $profile->setPreference("network.http.referer.defaultReferer", "https://www.google.com.br"); // Define referer padrão |
| 208 | + $profile->setPreference("network.http.referer.spoofSource", true); // Permite spoofing do referer |
| 209 | + $profile->setPreference("network.http.referer.trimmingPolicy", 0); // Não corta o referer |
194 | 210 |
|
195 | | - $options = new FirefoxOptions(); |
196 | | - $options->setProfile($profile); |
| 211 | + $options = new FirefoxOptions(); |
| 212 | + $options->setProfile($profile); |
197 | 213 |
|
198 | | - $capabilities = DesiredCapabilities::firefox(); |
199 | | - $capabilities->setCapability(FirefoxOptions::CAPABILITY, $options); |
| 214 | + $capabilities = DesiredCapabilities::firefox(); |
| 215 | + $capabilities->setCapability(FirefoxOptions::CAPABILITY, $options); |
| 216 | + } |
200 | 217 |
|
201 | 218 | try { |
202 | 219 | $driver = RemoteWebDriver::create($host, $capabilities); |
|
0 commit comments