Reputation: 600
Can https://www.teamdev.com/dotnetbrowser run on a IIS .NET server only? We want to:
1) Use ASP.NET to create a new thread upon a certain user action
2) load various DOMs from various external websites into instances if it
3) wait 30 seconds for each one so their image carousels can load up various images
4) inspect DOMs during that 30 second wait to see what new images get loaded via Ajax
5) record the URLs of those images
Upvotes: 1
Views: 216
Reputation: 259
Yes, you can use DotNetBrowser in IIS environment using the off-screen mode.
The next sample displays how to create basic ASP.NET controller that uses DotNetBrowser.
public class BrowserController : Controller
{
private Browser dotNetBrowser;
protected override void Initialize(RequestContext requestContext)
{
base.Initialize(requestContext);
//Create off-screen browser instance
dotNetBrowser = BrowserFactory.Create();
//Subscribe to the web page loaded event
dotNetBrowser.DocumentLoadedInFrameEvent += DotNetBrowser_DocumentLoadedInMainFrameEvent;
}
public ActionResult UrlHandle()
{
string url = "google.com"; //Set URL you need to load
dotNetBrowser.LoadURL(url);
return View();
}
private void DotNetBrowser_DocumentLoadedInMainFrameEvent(object sender, FrameLoadEventArgs frameLoadEventArgs)
{
//Get image references from DOM
IEnumerable<string> imageReferences = dotNetBrowser.GetDocument()
.GetElementsByTagName("img")
.Select(element => (element as DOMElement)?.Attributes["src"]);
foreach (string imageReference in imageReferences)
{
//Do whatever you need
Console.WriteLine(imageReference);
}
//Dispose browser instance after all required actions
dotNetBrowser.Dispose();
}
}
You can find useful information related to your goals by the following links:
Resource handling - https://dotnetbrowser.support.teamdev.com/support/solutions/articles/9000110154-handling-resources-loading
Ajax requests handling - how to get ajax request response body using dotnetbrowser?
Upvotes: 0