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 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝