N
nathanvj
Guest
Im trying to make an application where the user can paste a bunch of links into a textbox (tbLinks) and then click on the Start button (btnStart) to check the NAME, PRICE, and STOCK (respectively lblName, lblPrice and lblStock).
When I run the following code, I need to click the Start button (btnStart) twice, and then it returns only the name, price and stock of the first URL.
private void btnStart_Click(object sender, EventArgs e)
{
// Check if any links are entered
if(tbLinks.Text == "")
{
MessageBox.Show("You have to enter atleast one link to start.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
// Make list to store links to products
List<string> links = new List<string>();
// Add every link that has been entered into the list for the links
for (int i = 0; i < tbLinks.Lines.Length; i++)
{
links.Add(tbLinks.Lines);
}
// For every link that has been entered
foreach (string link in links)
{
// Visit the link using the browser
wbAliexpress.Navigate(link);
// Get the product price and check if it isnt null
HtmlElement ProductPrice = wbAliexpress.Document.GetElementById("j-sku-discount-price");
if(ProductPrice != null) {
// The title of the document that will be set into the lblName shouldnt be bigger than the maxLength
var maxLength = 15;
if (wbAliexpress.DocumentTitle.Length <= maxLength)
{
lblName.Text += wbAliexpress.DocumentTitle + System.Environment.NewLine;
} else {
var newTitle = wbAliexpress.DocumentTitle.Substring(0, maxLength);
lblName.Text += newTitle + System.Environment.NewLine;
}
// Find prices and stock and enter them into the labels lblPrice and lblStock
lblPrice.Text += wbAliexpress.Document.GetElementById("j-sku-discount-price").OuterText + System.Environment.NewLine;
lblStock.Text += wbAliexpress.Document.GetElementById("j-sell-stock-num").OuterText + System.Environment.NewLine;
}
}
}
Can someone help me out here? Is it because the browser cant handle so many requests at once?
Thank you in advance,
Nathan
Continue reading...
When I run the following code, I need to click the Start button (btnStart) twice, and then it returns only the name, price and stock of the first URL.
private void btnStart_Click(object sender, EventArgs e)
{
// Check if any links are entered
if(tbLinks.Text == "")
{
MessageBox.Show("You have to enter atleast one link to start.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
// Make list to store links to products
List<string> links = new List<string>();
// Add every link that has been entered into the list for the links
for (int i = 0; i < tbLinks.Lines.Length; i++)
{
links.Add(tbLinks.Lines);
}
// For every link that has been entered
foreach (string link in links)
{
// Visit the link using the browser
wbAliexpress.Navigate(link);
// Get the product price and check if it isnt null
HtmlElement ProductPrice = wbAliexpress.Document.GetElementById("j-sku-discount-price");
if(ProductPrice != null) {
// The title of the document that will be set into the lblName shouldnt be bigger than the maxLength
var maxLength = 15;
if (wbAliexpress.DocumentTitle.Length <= maxLength)
{
lblName.Text += wbAliexpress.DocumentTitle + System.Environment.NewLine;
} else {
var newTitle = wbAliexpress.DocumentTitle.Substring(0, maxLength);
lblName.Text += newTitle + System.Environment.NewLine;
}
// Find prices and stock and enter them into the labels lblPrice and lblStock
lblPrice.Text += wbAliexpress.Document.GetElementById("j-sku-discount-price").OuterText + System.Environment.NewLine;
lblStock.Text += wbAliexpress.Document.GetElementById("j-sell-stock-num").OuterText + System.Environment.NewLine;
}
}
}
Can someone help me out here? Is it because the browser cant handle so many requests at once?
Thank you in advance,
Nathan
Continue reading...