海运的博客

此内容被密码保护

发布时间:January 17, 2015 // 分类: // No Comments

请输入密码访问

PHP使用Selenium自动化运行chrome/firefox

发布时间:June 26, 2014 // 分类:PHP // 1 Comment

overviewSelenium.png
通过composer安装php-webdriver:

apt install php7.4-cli php-curl php-zip
curl -sS https://getcomposer.org/installer | php --install-dir=/usr/bin/
php composer.phar require php-webdriver/webdriver 

安装java环境和selenium server:

apt install openjdk-14-jre
wget https://selenium-release.storage.googleapis.com/3.141/selenium-server-standalone-3.141.59.jar
java -jar selenium-server-standalone-3.141.59.jar 

安装firefox/chrome浏览器和相应的webdirver:

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
apt install ./google-chrome-stable_current_amd64.deb 
wget https://chromedriver.storage.googleapis.com/88.0.4324.96/chromedriver_linux64.zip
unzip chromedriver_linux64.zip 
mv chromedriver /usr/bin/
apt install firefox
wget https://github.com/mozilla/geckodriver/releases/download/v0.29.0/geckodriver-v0.29.0-linux64.tar.gz
tar zxf geckodriver-v0.29.0-linux64.tar.gz 
mv geckodriver /usr/bin/

启动浏览器需X环境支持,可使用XVNCX Window
可以使用Firefox扩展Selenium IDE: PHP Formatters录制脚本。
selenium chrome使用:

<?php
require_once('vendor/autoload.php');
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Chrome\ChromeOptions;

$host = 'http://localhost:4444/wd/hub';
$options = new ChromeOptions();
$options->addArguments(array(
        '--no-sandbox',
        '--headless',
        '--start-maximized',
        '--user-data-dir=/tmp/chrome-user-data-dir',
        '--profile-directory=/tmp/chrome-profile-dir',
        '--user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36'
));
$caps = DesiredCapabilities::chrome();
$caps->setCapability(ChromeOptions::CAPABILITY, $options);
$driver = RemoteWebDriver::create($host, $caps);
//default
//$driver = RemoteWebDriver::create($host, DesiredCapabilities::chrome());
//$driver->manage()->window()->maximize();
$driver->get('https://www.haiyun.me/');
var_dump($driver->getTitle());
$driver->quit();

selenium firefox使用:

<?php
namespace Facebook\WebDriver;
require 'vendor/autoload.php';
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Firefox\FirefoxProfile;
use Facebook\WebDriver\Firefox\FirefoxDriver;

$host = 'http://localhost:4444/wd/hub';
$profile = new FirefoxProfile();
$profile->setPreference('browser.startup.homepage', 'https://github.com/facebook/php-webdriver/');
$profile->setPreference("general.useragent.override", "Mozilla/5.0");
//$profile->addExtension('./vimperator-3.8.2-fx.xpi');
$caps = DesiredCapabilities::firefox(); 
$caps->setCapability(FirefoxDriver::PROFILE, $profile); 
$caps->setCapability('moz:firefoxOptions', ['args' => ['-headless']]);
$caps->setCapability('moz:firefoxOptions', ['args' => ["-profile", "/tmp/firefox_profile"]]);
$driver = RemoteWebDriver::create($host, $caps);

//default
//$driver = RemoteWebDriver::create($host, DesiredCapabilities::firefox());
$driver->manage()->window()->maximize();
$driver->get('https://www.haiyun.me/');
var_dump($driver->getTitle());
$driver->quit();

文档:
https://github.com/php-webdriver/php-webdriver/wiki
https://php-webdriver.github.io/php-webdriver/

Windows7设置Firefox为默认浏览器

发布时间:August 18, 2013 // 分类:Firefox // No Comments

Windows Registry Editor Version 5.00
 
[HKEY_CLASSES_ROOT\Firefox]
@="Firefox Document"
[HKEY_CLASSES_ROOT\Firefox\Shell]
[HKEY_CLASSES_ROOT\Firefox\Shell\open]
[HKEY_CLASSES_ROOT\Firefox\Shell\open\command]
@="\"D:\\Program Files\\Firefox\\Firefox.exe\" \"%1\""
[HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice]
"Progid"="Firefox"

AutoHotkey调用KeePass快速输入密码

发布时间:March 2, 2013 // 分类:AutoHotKey // No Comments

通过AutoHotkey快速启动KeePass并在当前页面自动输入密码,首先自定义函数,方便多个程序下调用。

keepass()
{
DetectHiddenWindows, On
IfWinExist Data.kdbx
{
  Send ^!a
}
else
  {
  DetectHiddenWindows, On
  IfWinExist ahk_class WindowsForms10.Window.8.app.0.2bf8098_r13_ad1
    {
    Send ^!k 
        IfWinNotActive  打开数据库
        {
            Send ^!k
        }
    WinWait 打开数据库
    Send www.haiyun.me{Enter}
    Sleep 1000
    Send ^!a
    }
    else
      {
      Run D:\Program Files\KeePass\KeePass.exe
      WinWait 打开数据库
      WinActivate
      Send www.haiyun.me{Enter}
      Sleep 1000
      Send ^!a
      }
}
}

火狐下通过快捷键调用KeePass快速输入密码,其它浏览器更改Ahk_Class:

#IfWinActive ahk_class MozillaWindowClass
::/p::
keepass()
Return
分类
最新文章
最近回复
  • crowjin: 你确定这能过滤??不是所有请求都返回空地址::?
  • : linux系统上单个网卡多条宽带拨号获取公网IP,外网可以访问这些IP,有偿! Q:25299...
  • 硅谷少年: 非常有用,感谢分享
  • spartan2: https://dashboard.hcaptcha.com/welcome_accessib...
  • 海运: 应该能,在购买页面先手工跳过cf机器验证,后续一定时间内不更换ip应该不会再次验证。
  • spartan: 大佬斯巴达开启了CF的机器识别验证,请问插件能自动跳过吗? 另外这个脚本有没有简单使用说明,新...
  • vincent: 膜拜大佬
  • 海运: proxy-header或proxy_protocol
  • liangjw: 如果是 内部调用 或者 中间存在 代理 而上一个代理又在内网 ,那怎么处理来自代理私有IP?
  • chainofhonor: 感谢,用dnsmasq设置自动判断BIOS和UEFI成功了