gpt4 book ai didi

html - 我如何使用 Watir 直接从文件中读取(解析)html?

转载 作者:太空宇宙 更新时间:2023-11-03 16:05:55 24 4
gpt4 key购买 nike

当然,我已经可以用 Nokogiri 做到这一点

doc = Nokogiri::HTML(src)

其中 src 是我数据库中的一个文本列。

但我真的很喜欢 Watir 的开发者搜索界面,而不是 Nokogiri。

到目前为止,在我在互联网上的搜索中,没有太多证据表明如何做到这一点,即。对于非托管 html。

最佳答案

您可以通过在文件路径的开头添加“file://”来访问本地 html 文件(参见我的 blog post on the topic)。

例如,假设您的计算机上有一个 html 文件,位于“C:\users\testuser\desktop\test_file.html”。

如果你想打开这个文件并使用 Watir 与之交互,你可以这样做:

browser = Watir::Browser.new
browser.goto('file://C:\users\testuser\desktop\test_file.html')

然后您就可以像通常与 Watir 一样与浏览器/页面/html 进行交互了。

注意:如果您在尝试与浏览器交互时收到 NoMethodError: unknown property or method: 'document' 异常,请确保您的浏览器是由具有管理权限的用户打开的。

关于html - 我如何使用 Watir 直接从文件中读取(解析)html?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13982725/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com