海运的博客

此内容被密码保护

发布时间: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
分类
最新文章
最近回复
  • 海运: 恩山有很多。
  • swsend: 大佬可以分享一下固件吗,谢谢。
  • Jimmy: 方法一 nghtp3步骤需要改成如下才能编译成功: git clone https://git...
  • 海运: 地址格式和udpxy一样,udpxy和msd_lite能用这个就能用。
  • 1: 怎么用 编译后的程序在家里路由器内任意一台设备上运行就可以吗?比如笔记本电脑 m参数是笔记本的...
  • 孤狼: ups_status_set: seems that UPS [BK650M2-CH] is ...
  • 孤狼: 擦。。。。apcupsd会失联 nut在冲到到100的时候会ONBATT进入关机状态,我想想办...
  • 海运: 网络,找到相应的url编辑重发请求,firefox有此功能,其它未知。
  • knetxp: 用浏览器F12网络拦截或监听后编辑重发请求,修改url中的set为set_super,将POS...
  • Albert: 啊啊啊啊啊啊啊啊啊 我太激动了,终于好了英文区搜索了半天,翻遍了 pve 论坛没找到好方法,博...