Hello All,
I ran into a wall today and I was wondering if anybody could help.The code below iterates through a webpage's html. The pages.page1 class contains my URL, and the method below is being used by a webbrowser1_documentcompleted to return the results to the list view and also stops upon completion of gathering data. I am able to do this to only one webpage, I am wondering , How do I iterate through two webpages with the code below ? Are there ways to manipulate the conditions to include another webpage with different attributes and elements ? thank you in advance.
sURL = RemoveHTTP(sURL);
if (sURL == (Pages.PAGE1))
{
HtmlElementCollection oCol1 = oDoc.Body.GetElementsByTagName("input");
foreach (HtmlElement oElement in oCol1)
{
if (oElement.GetAttribute("id").ToString() == "ProductNum")
{
oElement.SetAttribute("value", ProductNbr);
}
if (oElement.GetAttribute("id").ToString() == "SubmitBtn")
{
oElement.InvokeMember("click");
}
}
}
if (sURL.Contains(Pages.PAGE2))
{
HtmlElementCollection oCol1 = oDoc.Body.GetElementsByTagName("tr");
foreach (HtmlElement oElement1 in oCol1)
{
if (oElement1.GetAttribute("data-Value").ToString() == ProductNbr.ToUpper())
{
HtmlElementCollection oCol2 = oElement1.GetElementsByTagName("td");
foreach (HtmlElement oElement2 in oCol2)
{
if (oElement2 != null)
{
if (oElement2.InnerText != null)
{
if (oElement2.InnerText.StartsWith("$"))
{
string sPrice = oElement2.InnerText.Replace("$", "").Trim();
double dblPrice = double.Parse(sPrice);
if (dblPrice > 0)
m_dblPrices.Add(dblPrice);
}
}
}
}
}
}