浏览器自动化:Python + Firefox 使用 PyXPCOM

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1020524/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 21:16:59  来源:igfitidea点击:

Browser automation: Python + Firefox using PyXPCOM

pythonfirefoxautomation

提问by George

I have tried Pamiea browser automation library for internet explorer. It interfaces IE using COM, pretty neat:

我已经尝试了Pamie一个用于 Internet Explorer 的浏览器自动化库。它使用 COM 连接 IE,非常简洁:

import PAM30
ie = PAM30.PAMIE("http://user-agent-string.info/")
ie.clickButton("Analyze my UA")

Now I would like to do the same thing using PyXPCOMwith similar flexibility on Firefox. How can I do this? Can you provide sample code?

现在我想在 Firefox 上使用具有类似灵活性的PyXPCOM做同样的事情。我怎样才能做到这一点?你能提供示例代码吗?

update: please only pyxpcom

更新:请只使用 pyxpcom

回答by Geo

I've used webdriverwith firefox. I was very pleased with it.

我在Firefox 中使用了webdriver。我对此非常满意。

As for the code examples, thiswill get you started.

至于代码示例,将使您入门。

回答by Vitorio

My understanding of PyXPCOM is that it's meant to let you create and access XPCOM components, not control existing ones. You may not be able to do this using PyXPCOM at all, per Mark Hammond, the original author:

我对 PyXPCOM 的理解是,它旨在让您创建和访问 XPCOM 组件,而不是控制现有组件。根据原作者 Mark Hammond 的说法,您可能根本无法使用 PyXPCOM 执行此操作:

It simply isn't what XPCOM is trying to do. I'm not sure if Mozilla/Firefox now has or is developing a COM or any other "automation" mechanism.

这根本不是 XPCOM 想要做的。我不确定 Mozilla/Firefox 现在是否拥有或正在开发 COM 或任何其他“自动化”机制。

and:

和:

If by "automating", you mean "controlling Mozilla via a remote process via xpcom", then as far as I know, that is not possible

如果“自动化”是指“通过 xpcom 通过远程进程控制 Mozilla”,那么据我所知,这是不可能的

You may instead want to take a look at the previously-suggested Webdriver project, Windmill, or MozMill, both of which support automating Firefox/Gecko/XULRunner via Python.

相反,您可能想查看之前推荐的 Webdriver 项目WindmillMozMill,它们都支持通过 Python 自动化 Firefox/Gecko/XULRunner。

回答by Eric Wendelin

If you're testing a webapp and want to write Python to do it, check out Selenium RCso you can use the same API for all browsers.

如果您正在测试 Web 应用程序并希望编写 Python 来完成它,请查看Selenium RC,以便您可以对所有浏览器使用相同的 API。