首页 文章

正确的xpath返回空结果

提问于
浏览
0

我想从这个网页上的表格中抓取数据http://www.changning.sh.cn/jact/front/front_mailpublist.action?sysid=9

在编写蜘蛛之前,我在Scrapy shell中测试了我的Xpath表达式,但遇到了一个问题:Xpath无法从表中获取任何文本 .

enter image description here

假设我想在左上角单元格中提取文本LM2015122827458,我使用 response.xpath("//tr[@class = 'tr_css']/td[1]/text()").extract() . 只返回一个空列表 . 我尝试了替代的Xpath表达式,包括受Chrome "copy Xpath,"启发但没有运气的表达式 . 我甚至使用 response.xpath("//text()") 来提取页面上的所有文本,看看LM2015122827458是否存在 . 它没有't. So, is this a page that Xpath can'吨处理?或者我做错了什么?非常感谢你!

1 回答

  • 0

    这个Xpath对我来说很好: -

    //tr[@class='tr_css'][1]/td[@class='text-center'][1]
    

    下面java中的代码工作对我来说很好: -

    driver.get("http://www.changning.sh.cn/jact/front/front_mailpublist.action?sysid=9");
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        String a = driver.findElement(By.xpath("//tr[@class='tr_css'][1]/td[@class='text-center'][1]")).getText();
        System.out.println(a);
    

    希望它能帮到你:)

相关问题