【发布时间】:2018-07-13 05:21:19
【问题描述】:
我正在尝试使用 .Net、Selenium、PhantomJs 解析以下网页 https://shop.sprouts.com/shop/flyer。我在元素文本中看到的数据与我在屏幕上看到的完全不同。有没有更好的方法来解析网页?
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.PhantomJS;
[TestClass]
public class UnitTest1
{
const string PhantomDirectory = @"..\..\..\packages\PhantomJS.2.1.1\tools\phantomjs";
[TestMethod]
public void GetSproutsWeeklyAdDetails()
{
using (IWebDriver phantomDriver = new PhantomJSDriver(PhantomDirectory))
{
phantomDriver.Navigate().GoToUrl("https://shop.sprouts.com/shop/flyer");
var elements = phantomDriver.FindElements(By.ClassName("cell-title-text"));
}
}
}
【问题讨论】:
-
改用 chromedriver。它已经支持无头模式。
-
感谢@baudan 的意见。我会试试看。
标签: .net selenium selenium-webdriver phantomjs headless