【问题标题】:How to Collect information from WebSite Into c# array with Selenium?如何使用 Selenium 从网站收集信息到 c# 数组中?
【发布时间】:2019-05-29 21:55:23
【问题描述】:

我想用 Selenium 在 C# 中将一些指定的数字收集到一个数组中。 但是有一个问题! This is 这些数字的 IMG!

每一行都在<div> 标记中,每个数字都在另一个<div> 标记中,如下所示:

<div>
     <div>
          Here is The Number!
     </div>
</div>

现在如何将所有这些数字导出到数组中?

【问题讨论】:

  • 您的代码试用版?
  • @DebanjanB 我没有测试任何代码
  • 您如何判断哪种解决方案有效,哪种无效?
  • @Arashmoghadas 参考MCVE

标签: c# html arrays selenium selenium-webdriver


【解决方案1】:

首先你需要使用类似的东西来获取列表中的所有崩溃行

public List<IWebElements> GetAllCrashRows()
{
driver.FindElements(By.Xpath("//div[starts-with(@class,'crash-row crash')]"));
}

一旦你获取了 List 中的所有行,你需要使用 foreach 循环获取所有内部行:

public List<IWebElement> GetAllRows(){
List<IWebElement> allRows = new List<IWebElement>();
foreach(var row in GetAllCrashRows())
{
//here u gonna get each row with data inside your rows that you already have using nested element (row)
 allrows.Add(row.FindEleemnts("//div[starts-with(@class,'col h-col')]"));
}
return allRows;
}
//Then u need another foresch loop to get text with data for each inner row
public List<string> GetRowsData(){
List<string> allRowsData = new List<string>();
foreach(var data in GetAllRows())
{
 allRowsData.Add(data.Text)
}
return allRowsData;
}

如果有不清楚的地方请告诉我。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-07
    • 1970-01-01
    • 1970-01-01
    • 2021-10-30
    • 1970-01-01
    • 2012-01-22
    • 1970-01-01
    • 2013-05-31
    相关资源
    最近更新 更多