selenium chromedriver php被检测为机器人

时间:2017-12-28 17:10:23

标签: php selenium selenium-webdriver selenium-chromedriver screen-scraping

只是想知道是否有人能够对我遇到的问题提供任何见解。我正在尝试使用硒和铬氢化合物刮去一个地方。该网站似乎总是检测到chromedriver browswer作为机器人。这是我的配置,我该如何避免这种检测?

Selenium构建信息

构建信息:版本:' 3.8.1',修订版:' 6e95a6684b',时间:' 2017-12-01T19:05:32.194Z' 系统信息:主持人:' localhost',ip:' 127.0.0.1',os.name:' Linux',os.arch:' amd64& #39;,os.version:' 3.13.0-108-generic',java.version:' 1.8.0_151'

我使用的是ChromeDriver 2.33.506092。任何帮助表示赞赏

<?php
    // An example of using php-webdriver.
    namespace Facebook\WebDriver;
    use Facebook\WebDriver\Chrome\ChromeOptions;
    use Facebook\WebDriver\Remote\DesiredCapabilities;
    use Facebook\WebDriver\Remote\RemoteWebDriver;
    require_once dirname(__FILE__) .'/vendor/autoload.php';

$userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36';


$host = 'http://localhost:4321/wd/hub';
$url = $host;
$options = new ChromeOptions();
// Setting the binary is optional.
//$options->setBinary('/bin/chromedriver');

// Available options:
// http://peter.sh/experiments/chromium-command-line-switches/
$options->addArguments(array(
    //'--window-size=571,428',
  // '--start-maximized',
//  '--headless',
    "--disable-gpu", "--window-size=1920,1080", "--no-sandbox",
    '--user-agent=' . $userAgent,
    "disable-infobars"

));



// Setting extensions is also optional
//$options->addExtensions(array(
//    '/path/to/chrome/extension1.crx',
//    '/path/to/chrome/extension2.crx',
//));

$caps = DesiredCapabilities::chrome();
$caps->setPlatform('WINDOWS');
$caps->setCapability(ChromeOptions::CAPABILITY, $options);

$driver = RemoteWebDriver::create($url, $caps,5000);



$driver->manage()->deleteAllCookies();
$url2 = 'https://www.realtor.ca/Residential/Map.aspx#CultureId=1&ApplicationId=1&RecordsPerPage=9&MaximumResults=9&PropertySearchTypeId=1&TransactionTypeId=2&StoreyRange=0-0&BedRange=0-0&BathRange=0-0&LongitudeMin=-156.0498046875&LongitudeMax=-16.9189453125&LatitudeMin=34.88592973581311&LatitudeMax=72.71190267150946&SortOrder=A&SortBy=1&viewState=m&ZoomLevel=4&PropertyTypeGroupID=1';

$driver->get($url2);
sleep(20)  ;
$cookies = $driver->manage()->getCookies();

0 个答案:

没有答案