相关疑难解决方法(0)

如何使用jquery隐藏除一个元素之外的所有元素?

我有HTML页面:

<head></head>
<body>
  <div>
    <div>
      <div id="myDiv">
      </div>
    </div>
  </div>
</body>
Run Code Online (Sandbox Code Playgroud)

如何隐藏所有div,并使用jquery将myDiv置于体内?

更新

该页面可能包含一些其他html元素,如一些表,锚点,p,我只想查看myDiv元素.

jquery

45
推荐指数
3
解决办法
7万
查看次数

截图后PhantomJS的内存消耗量很大

我通过Selenium使用PhantomJS,并在一个网站上遇到了大量图片的问题.

当我试图截取幻像时,PhantomJS进程内存消耗非常高,≈400-450MB(屏幕截图前≈100MB)

随着--load-images=no它更好,≈70-100MB.

有没有办法解决这个问题而不完全禁用图像?也许只能截取可见区域的截图而不是整页?

与其他WebDrivers(如Chrome)一起工作正常.

class Program
{
    public static RemoteWebDriver CreatePhantomJsDriver()
    {
        var service = PhantomJSDriverService.CreateDefaultService();
        //service.AddArgument("--load-images=no");

        var options = new PhantomJSOptions();
        options.AddAdditionalCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36");

        return new PhantomJSDriver(service, options);
    }

    public static void SaveScreenshot(RemoteWebDriver driver)
    {
        try
        {
            driver.TakeScreenshot().SaveAsFile(DateTime.Now.Ticks + ".jpg", ImageFormat.Jpeg);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }

    static void Main(string[] args)
    {
        using (var driver  = CreatePhantomJsDriver())
        {
            driver.Manage().Window.Size = new Size(1600, 1200);

            driver.Url = …
Run Code Online (Sandbox Code Playgroud)

c# selenium phantomjs selenium-webdriver

19
推荐指数
1
解决办法
919
查看次数

如何使用phantomjs呈现html元素

我想将图像保存在代码中指定的div内.但是使用下面的代码我会得到一些其他的部分.这是正确的方法吗?我只是phantomjs的初学者.所以请帮助.

var page = require('webpage').create();

page.open("http://n1k0.github.io/casperjs/#phantom_Casper_captureSelector", function    (status) {
    if (status !== 'success') {
        console.log('Unable to load the address!');
    } else {

        var clipRect = page.evaluate(function () { 
        return document.querySelector(".span7 demo").getBoundingClientRect(); });
        page.clipRect = {
            top:    clipRect.top,
            left:   clipRect.left,
            width:  clipRect.width,
            height: clipRect.height
        };



        window.setTimeout(function () {
            page.render('capture.png');
            phantom.exit();
        }, 200);
    }
});
Run Code Online (Sandbox Code Playgroud)

javascript phantomjs

10
推荐指数
1
解决办法
1万
查看次数