I'm working a project that web scrapes a table for work. The website I was trying to connect to using C# WebClient libray isn't working as I need to first connect to the Website, then simulate clicking on the "Next button" to go to the next page in the table.
The code I'm using right now looks like this,
This is to connect to website with the while looking up a name:
string urlParams = "lastName=John&firstName=Doe&PropertyID=&Submit=Serch+Properties"
using(WebClient client = new WebClient())
{
client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
htmlResult = client.UploadString(url, urlParams);
}
Then once I have the initial search I look to see if I can click next using HtmlAglityPack. If I can then I try to by send the parameters in the url.
HtmlDocument doc = new
doc.LoadHtml(htmlResult);
// I get the xpath from google chrome dev tools, inspect element and right click copy xpath
HtmlNode nextButton = doc.DocumentNode.SelectNode(selectNodeXPath);
if(nextButton && nextButton.InnerHtml == "Next")
{
// right now just trying to see the second page.
urlParams = "lastName=John&firstName=Doe&PropertyID=&Submit=Serch+Properties&SearchLocation=" + 1;
client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
htmlResult = client.UploadString(url, urlParams);
}
After I do this the htmlResult is null.