python - 使用 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]",这是怎么回事?
解决方案
推荐阅读
- python - 在 tensorflow 中使用预训练的对象检测模型。使用了哪些参数?
- ios - 当键盘出现时 CollectionView 向上移动然后返回到之前的位置
- html - 不同的图像大小取决于视口
- html - 如何将 CSS 应用于 HTML DIV 标签?
- dataframe - 用例类修剪 DataFrame
- c# - 没有足够的可用内存来运行此程序,Outlook MAPI 错误 - MailItem.SaveAs 方法 C#
- html - 如何更改列表中项目的缩进
- python-2.7 - 当我关闭 bash 终端时 gunicorn 和 python 不起作用
- eclipse - Linux 深色主题上的 Eclipse UI
- angularjs - 带有 URL 参数的 Angular 路由在 GoogleAppEngine/AWS S3 中部署时不起作用,但在 LocalHost/LocalIP 中完美运行