Parsing HTML table data with xpath and selenium in java

前端 未结 4 1107
清歌不尽
清歌不尽 2020-12-10 09:49

I want to take the data and organize it without the tags. It looks something like this

4条回答
  •  自闭症患者
    2020-12-10 10:33

    CSharp method to extract any table in a 2 dimension array:

    private string[,] getYourSpecTable(){
        return getArrayBy(By.CssSelector("table.SpecTable tr"), By.CssSelector("td"));
    }
    
    private string[,] getArrayBy(By rowsBy, By columnsBy){
        bool init=false;
        int nbRow=0, nbCol=0;
        string[,] ret = null;
        ReadOnlyCollection rows = this.webDriver.FindElements(rowsBy);
        nbRow = rows.Count;
        for(int r=0;r cols = rows[r].FindElements(columnsBy);
            if(!init) {
                init= true;
                nbCol = cols.Count;
                ret = new string[rows.Count, cols.Count];
            }                
            for(int c=0;c

提交回复
热议问题