duaiwo9093 2015-03-01 16:51
浏览 157
已采纳

xpath无法从表中提取数据

I write the following xpath to extract name and price from table.

/html/body/div[2]/div[7]/div[3]/table[1]/tbody/tr

http://www.iranjib.ir/showgroup/28/%D9%82%DB%8C%D9%85%D8%AA-%D8%B1%D9%88%D8%B2-%D9%85%D9%88%D8%A8%D8%A7%DB%8C%D9%84/

but it can't extract

  • 写回答

1条回答 默认 最新

  • doucheng3407 2015-03-01 17:11
    关注

    There is no tbody element in the source HTML of that page (try this yourself by opening the source document and searching for "tbody").

    Unfortunately, browsers (including browser plugins, n.b.) tend to add tbody elements to the DOM representations even if they are not actually there.

    I have no idea what you are trying to find on that page (you did not explain it clearly enough), but if you were searching for

    //table/tbody/tr
    

    and that did not return anything, the first thing you should try instead is

    //table//tr
    

    and see if it makes a difference. If it doesn't, the next thing to look out for is namespaces. The document that serves as your input (allegedly) is XHTML, which requires elements to be in a namespace:

    <html lang="fa" xml:lang="fa" xmlns="http://www.w3.org/1999/xhtml">
    

    Depending on the XPath engine you are using (again, we don't know), you need to cleanly register namespaces with prefixes, and prefix element names.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛