Selenium.PhantomJS is invalid namespace

2019-07-14 00:09发布

问题:

I am really trying my best to find a way to web scrape a website using javascript to load the pages so I can scrape lets say my playlist for example. I have had no luck with chrome driver nor phantomjs. Please have a look below and see if you can help me with the error.

using OpenQA.Selenium;
//The type or namespace 'PhantomJS' does not exist in the namespace 'OpenQASelenium'
using OpenQA.Selenium.PhantomJS;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace MusicScaper
{
    class TidalScraper
    {
    }
}

My packages.config file is as follows:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="HtmlAgilityPack" version="1.8.7" targetFramework="net461" />
  <package id="PhantomJS" version="2.1.1" targetFramework="net461" />
  <package id="Selenium.Support" version="3.14.0" targetFramework="net461" />
  <package id="Selenium.WebDriver" version="3.14.0" targetFramework="net461" />
</packages>

回答1:

The .NET language bindings marked the PhantomJS driver classes deprecated in 3.11, and those classes were removed in 3.14. The PhantomJS project and its driver are no longer being maintained, and the driver code has not (and will not) be updated to support the W3C WebDriver Specification. The preferred “headless” solution is to use Chrome or Firefox in headless mode, as both of those browsers and their drivers support such an operating mode. Alternatively, if you have your heart set on PhantomJS, and you don’t care about cross-browser execution, you can simply use the PhantomJS executable and automate it through its internal JavaScript API.