• <legend id='CQHeT'><style id='CQHeT'><dir id='CQHeT'><q id='CQHeT'></q></dir></style></legend>

    <small id='CQHeT'></small><noframes id='CQHeT'>

      <i id='CQHeT'><tr id='CQHeT'><dt id='CQHeT'><q id='CQHeT'><span id='CQHeT'><b id='CQHeT'><form id='CQHeT'><ins id='CQHeT'></ins><ul id='CQHeT'></ul><sub id='CQHeT'></sub></form><legend id='CQHeT'></legend><bdo id='CQHeT'><pre id='CQHeT'><center id='CQHeT'></center></pre></bdo></b><th id='CQHeT'></th></span></q></dt></tr></i><div id='CQHeT'><tfoot id='CQHeT'></tfoot><dl id='CQHeT'><fieldset id='CQHeT'></fieldset></dl></div>

    1. <tfoot id='CQHeT'></tfoot>
          <bdo id='CQHeT'></bdo><ul id='CQHeT'></ul>
      1. 在java中使用xpath和selenium解析HTML表格数据

        Parsing HTML table data with xpath and selenium in java(在java中使用xpath和selenium解析HTML表格数据)

          <tfoot id='pkyGC'></tfoot>
        • <small id='pkyGC'></small><noframes id='pkyGC'>

            <tbody id='pkyGC'></tbody>
                  <bdo id='pkyGC'></bdo><ul id='pkyGC'></ul>
                  <i id='pkyGC'><tr id='pkyGC'><dt id='pkyGC'><q id='pkyGC'><span id='pkyGC'><b id='pkyGC'><form id='pkyGC'><ins id='pkyGC'></ins><ul id='pkyGC'></ul><sub id='pkyGC'></sub></form><legend id='pkyGC'></legend><bdo id='pkyGC'><pre id='pkyGC'><center id='pkyGC'></center></pre></bdo></b><th id='pkyGC'></th></span></q></dt></tr></i><div id='pkyGC'><tfoot id='pkyGC'></tfoot><dl id='pkyGC'><fieldset id='pkyGC'></fieldset></dl></div>

                  <legend id='pkyGC'><style id='pkyGC'><dir id='pkyGC'><q id='pkyGC'></q></dir></style></legend>

                  本文介绍了在java中使用xpath和selenium解析HTML表格数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想获取数据并在没有标签的情况下对其进行组织.它看起来像这样

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

                  <table class="SpecTable">
                      <col width="40%" />
                      <col width="60%" />
                      <tr>
                          <td class="LightRowHead">Optical Zoom:</td>
                          <td class="LightRow">15x</td>
                      </tr>
                      <tr>
                          <td class="DarkRowHead">Digital Zoom:</td>
                          <td class="DarkRow">6x</td>
                      </tr>
                      <tr>
                          <td class="LightRowHead">Battery Type:</td>
                          <td class="LightRow">Alkaline</td>
                      </tr>
                      <tr>
                          <td class="DarkRowHead">Resolution Megapixels:</td>
                          <td class="DarkRow">14 MP</td>
                      </tr>
                  </table>
                  

                  我希望能够提取所有信息字符串,以便我可以将其存储在纯文本文件中:

                  and I want to be able to extract all the strings of information so that I can store in a plaintext file with just this:

                  光学变焦:15 倍数码变焦:6 倍电池类型:碱性分辨率百万像素:14 MP

                  Optical Zoom: 15x Digital Zoom: 6x Battery Type: Alkaline Resolution Megapixels: 14 MP

                  public static void main(String[] args) {
                  
                          FirefoxProfile profile = new FirefoxProfile();
                          profile.setPreference("general.useragent.override", "some UA string");
                          WebDriver driver = new FirefoxDriver(profile);
                  
                          String Url = "http://www.walmart.com/ip/Generic-14-MP-X400-BK/19863348";
                          driver.get(Url);
                          List<WebElement> resultsDiv = driver.findElements(By.xpath("//table[contains (@class,'SpecTable')//td"));
                  
                          System.out.println(resultsDiv.size());
                          for (int i=0; i<resultsDiv.size(); i++) {
                              System.out.println(i+1 + ". " + resultsDiv.get(i).getText());
                          }
                  

                  我正在使用 Selenium 进行 Java 编程,但我无法为它找出正确的 XPath 表达式.

                  I am programming in Java with Selenium and I cannot figure out the correct XPath expression for it.

                  有人能弄清楚我为什么会犯错,或许能给我一些关于如何正确解析这些数据的指示吗?我对 Selenium 和 XPaths 很陌生,但我需要这个来工作.

                  Can someone figure out why I err on this and maybe give me some pointers on how I can parse this data correctly? Im very new to Selenium and XPaths but I need this for work.

                  另外,如果有人有任何好的资源让我快速学习 Selenium 和 XPath,我们也将不胜感激!

                  Also if anyone has any good sources for me to learn Selenium and XPath fast, those would also be greatly appreciated!

                  推荐答案

                  这可能会满足您的需求:

                  Probably this will suite your needs:

                  string text = driver.findElement(By.cssSelector("table.SpecTable")).getText();
                  

                  String text 将包含来自具有类 SpecTable 的表的所有文本节点.我更喜欢使用 css,因为它受 IE 支持并且比 xpath 更快.但是对于 xpath 教程,请尝试 this 和 这个.

                  String text will contain all text nodes from the table with class SpecTable. I prefer using css, because it's supported by IE and faster than xpath. But as for xpath tutorials try this and this.

                  这篇关于在java中使用xpath和selenium解析HTML表格数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                    <tfoot id='2IGar'></tfoot>
                  • <small id='2IGar'></small><noframes id='2IGar'>

                        <legend id='2IGar'><style id='2IGar'><dir id='2IGar'><q id='2IGar'></q></dir></style></legend>
                          <tbody id='2IGar'></tbody>

                        1. <i id='2IGar'><tr id='2IGar'><dt id='2IGar'><q id='2IGar'><span id='2IGar'><b id='2IGar'><form id='2IGar'><ins id='2IGar'></ins><ul id='2IGar'></ul><sub id='2IGar'></sub></form><legend id='2IGar'></legend><bdo id='2IGar'><pre id='2IGar'><center id='2IGar'></center></pre></bdo></b><th id='2IGar'></th></span></q></dt></tr></i><div id='2IGar'><tfoot id='2IGar'></tfoot><dl id='2IGar'><fieldset id='2IGar'></fieldset></dl></div>

                            <bdo id='2IGar'></bdo><ul id='2IGar'></ul>