我正在使用selenium和Htmlaglity pack here是网站
这是我的代码
IWebDriver driver = new OpenQA.Selenium.PhantomJS.PhantomJSDriver("D:/Testing/");
driver.Navigate().GoToUrl(suburl);
Thread.Sleep(50000);
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(1000));
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(20));
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(driver.PageSource);
答案 0 :(得分:1)
您必须在获取PageSource之前切换到iframe。请参阅以下代码:
IWebDriver driver = new OpenQA.Selenium.PhantomJS.PhantomJSDriver("D:/Testing/");
driver.Navigate().GoToUrl(suburl);
Thread.Sleep(50000);
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(1000));
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(20));
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(driver.PageSource);
driver.SwitchTo().Frame(driver.FindElement(By.Id("blockrandom")));
HtmlAgilityPack.HtmlDocument iframeDoc = new HtmlAgilityPack.HtmlDocument();
iframeDoc.LoadHtml(driver.PageSource);