적절한 문서가 없기 때문에 HTML 내용을로드 한 후에 HtmlAgilityPack
이 C #의 화면 캡처를 지원하는지 잘 모르겠습니다.
그래서 HtmlAgilityPack을 사용하여 (또는 함께) 스크린 샷을 잡을 수있는 방법이 있습니까? 페이지 조작을 할 때마다 어떻게되는지 시각적 단서가 있습니까?
지금까지 내 작업 코드는 다음과 같습니다.
using HtmlAgilityPack;
using System;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
string urlDemo = "https://htmlagilitypack.codeplex.com/";
HtmlWeb getHtmlWeb = new HtmlWeb();
var doc = getHtmlWeb.Load(urlDemo);
var sentence = doc.DocumentNode.SelectNodes("//p");
int counter = 1;
try
{
foreach (var p in sentence)
{
Console.WriteLine(counter + ". " + p.InnerText);
counter++;
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
Console.ReadLine();
}
}
}
현재는 긁힌 자국과 출력 모든 p
콘솔에서 페이지를하지만 동시에 나는 긁어 내용의 화면 잡아 싶어하지만 시작하는 방법과 위치를 알 수 없습니다.
어떤 도움이라도 대단히 감사합니다. TIA
대신 Selenium WebDriver 를 사용할 수 있습니까?
먼저 다음 NuGet 패키지를 프로젝트에 추가해야합니다.
페이지를로드하고 스크린 샷을 찍는 것은 다음과 같이 간단합니다 ...
using System;
using System.Drawing.Imaging;
using System.IO;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;
namespace SeleniumTest
{
class Program
{
static void Main(string[] args)
{
// Create a web driver that used Firefox
var driver = new FirefoxDriver(
new FirefoxBinary(), new FirefoxProfile(), TimeSpan.FromSeconds(120));
// Load your page
driver.Navigate().GoToUrl("http://google.com");
// Wait until the page has actually loaded
var wait = new WebDriverWait(driver, new TimeSpan(0, 0, 10));
wait.Until(d => d.Title.Contains("Google"));
// Take a screenshot, and saves it to a file (you must have full access rights to the save location).
var myDesktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
((ITakesScreenshot)driver).GetScreenshot().SaveAsFile(Path.Combine(myDesktop, "google-screenshot.png"), ImageFormat.Png);
driver.Close();
}
}
}