账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    【求助】php-webdriver如何获取到渲染后的页面代码
    77
    0
    比如这个地址:https://y.qq.com/n/ryqq/songD...使用php-webdriver,获取到的不是渲染后的代码有办法可以获取到渲染后的页面代码吗?PS:不是为了抓此站的数据,请勿回复通过api接口获取数据,仅想知道php-webdriver是否能获取到渲染后的代码//php-webdriver$host = 'http://localhost:4444/wd/hub';$capabilities = DesiredCapabilities::chrome();$driver = RemoteWebDriver::create($host, $capabilities, 5000);$driver->get("https://y.qq.com/n/ryqq/songDetail/0039MnYb0qxYhV");$html = $driver->getPageSource();dump($html);
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 碎情漂移ド 普通会员 1楼

      在PHP中,可以通过Webdriver的getDriver().get('http://example.com').get('/home')来获取到渲染后的页面代码。这将返回一个Promise,当页面完全渲染完毕时,Promise将解析为HTML代码。

      例如:

      ```php $driver = new WebDriver();

      $driver->get('http://example.com');

      // 选择并打开 home 目录 $driver->get('/home');

      // 读取 HTML 代码 echo $driver->getDriver().get('http://example.com').get('/home').get('html'); ```

      注意,get('http://example.com').get('/home') 将返回整个页面的HTML代码,包括所有的CSS和JavaScript。如果你只想获取特定的元素或HTML结构,你可能需要使用其他方法,如get('http://example.com').get('/home').get('div')

      另外,getDriver().get('http://example.com').get('/home') 还可以设置一个回调函数来处理页面渲染的结果。例如:

      ```php $driver = new WebDriver();

      $driver->get('http://example.com');

      // 选择并打开 home 目录 $driver->get('/home');

      // 设置回调函数来处理页面渲染的结果 $driver->getDriver()->setCallback(function($result) { // 处理页面渲染的结果 echo $result . PHP_EOL; });

      // 读取 HTML 代码 echo $driver->getDriver().get('http://example.com').get('/home').get('html'); ```

      在这个例子中,回调函数将接收到一个Promise,表示页面已经完全渲染完毕。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部