首页 > 解决方案 > 使用 webbot 进行网页抓取会返回错误的内容

问题描述

我有这个简单的 html 代码:

<html>
    <head></head>
  <body>
    <p>
      <span class="bold-title">This is</span>
      " a test"
    </p>
  </body>
  </html>

我想通过它的 xpath 使用 webbot 来获得“测试”

似乎“工作”的代码是:

from webbot import Browser
driver = Browser(showWindow=True)
driver.go_to('file:///C:/Users/myself/Desktop/test.html')
outp = driver.execute_script("return document.evaluate('/html/body/p/text()', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;")
print(outp)

xpath "/html/body/p/text()" 理论上应该返回 "a test",但是 webbot 决定打印 "[None, None, None, None, None, None, None]",这是怎么回事?

标签: pythonweb-scrapingwebbot

解决方案


推荐阅读