简体   繁体   English

我如何获得多个价格数据并使用 Selenium 将它们排序并放入带有 c# 的标签?

[英]How can i get plural price data and put them order and put in labels with c# using Selenium?

I'm trying to do a price comparing website.我正在尝试做一个价格比较网站。 With this code, I can get the first product price.使用此代码,我可以获得第一个产品价格。 But I need to take 6 product prices and put their labels and with the "buy" button I wanna send users to buy link.但我需要获取 6 个产品价格并贴上标签,并使用“购买”按钮我想向用户发送购买链接。 Also, I wanna to order options like low to high or high to low.另外,我想订购从低到高或从高到低的选项。 How can I do that?我怎样才能做到这一点?

protected void Button0_Click0(object sender, EventArgs e)
{
    IWebDriver driver = new ChromeDriver();
    string str1, str2, str3, str4, str5, str6;
    driver.Url = "https://www.akakce.com/arama/?q=" + TextBox2.Text;
    driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
    str1 = driver.FindElement(By.XPath("//span[@class='pb_v8']//span[@class='pt_v8']")).GetAttribute("textContent");
    Label1.Text = ("Price: " + str1);
}

I've did some changes but str 1 is giving correct data first one but str 2 gives 4. product price and skipping 2 and 3. products prices.我做了一些更改,但 str 1 给出了第一个正确的数据,但 str 2 给出了 4. 产品价格并跳过 2 和 3. 产品价格。 Here my edited code:这是我编辑的代码:

IWebDriver driver = new ChromeDriver();
string str1, str2, str3, str4, str5, str6;
driver.Url = "https://www.akakce.com/arama/?q=" + TextBox2.Text;
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
str1 = driver.FindElement(By.XPath("//li[1]//a//span[@class='pb_v8']//span[@class='pt_v8']")).GetAttribute("textContent");
str2 = driver.FindElement(By.XPath("//li[2]//a//span[@class='pb_v8']//span[@class='pt_v8']")).GetAttribute("textContent");
Label1.Text = ("Price: " + str1);
Label2.Text = ("Price: " + str2);

First you need to click on lowest/highest price link and then use FindElements() to get list of elements and then iterate首先,您需要点击lowest/highest价格链接,然后使用FindElements()获取元素列表,然后迭代

//click on lowest to highest
driver.FindElement(By.XPath("//p[@class='lms_v8']//a[2]")).Click();
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(15);
IList<IWebElement> elements = 
driver.FindElements(By.XPath("//h3/following::span[1]//span[@class='pt_v8']"));
foreach (IWebElement element in elements)
    {
      Console.WriteLine(element.GetAttribute("textContent"));
    }

Add value in a string list and then assign it to index..0-5在字符串列表中添加值,然后将其分配给 index..0-5

//click on lowest to highest
            driver.FindElement(By.XPath("//p[@class='lms_v8']//a[2]")).Click();
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(15);
            IList<IWebElement> elements = driver.FindElements(By.XPath("//h3/following::span[1]//span[@class='pt_v8']"));
            List<string> prices = new List<string>();
            foreach (IWebElement element in elements)
            {
                prices.Add(element.GetAttribute("textContent"));
            }
            Console.WriteLine(prices[0]);
            Console.WriteLine(prices[1]);
            Console.WriteLine(prices[2]);
            Console.WriteLine(prices[3]);
            Console.WriteLine(prices[4]); 
            Console.WriteLine(prices[5]);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Selenium 获取在 class 和 C# 中找到的文本价格数据? - How can i get text price data found in a class with C# using Selenium? UNITY,我如何从另一个 C# class 获取所有属性并将它们放入枚举 - UNITY, How can I get all properties from another C# class and put them into an enum 可以设置一个数组来获取所有变量并将它们放入 C# WindowsForm 中的数据库或数据 gridview 中吗? - Can Set an array to get all of variable and put them into a database or data gridview in C# WindowsForm? C# Windows 窗体应用程序:如何使用循环将 5 个不同的数据放在 5 个不同的标签中 - C# Windows Form Application: How to put 5 different data in 5 different labels using a loop 如何使用Selenium找到所有元素并将它们放在列表中? - How can I find all elements and put them in a list using Selenium? 我怎么能延迟C#? - How can i put a delay with C#? 如何读取值并将其放入数组C# - how can read values and put them in Array C# 如何分离图像中的像素并将其放入C#数组中? - How can I separate the pixels in an image and put them into a C# array? 如何从Listbox(在C#中)中获取所有元素/字段并将它们放入DataTable中? - How can I take all the elements / fields from a Listbox (in C#) and put them into a DataTable? 我怎样才能把文本禁用<input>使用 selenium chrome 驱动程序和 c#? - How can i put text in disabled <input> with selenium chrome driver and c#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM