使用Python自动使用JavaScript表单登录网站 [英] Using Python to Automatically Login to a Website with a JavaScript Form

查看:90
本文介绍了使用Python自动使用JavaScript表单登录网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写登录到网站的特定脚本.这个特定的网站包含一个Javascript形式,因此使用机械化"对我几乎没有运气.

I'm attempting to write a particular script that logs into a website. This specific website contains a Javascript form so I had little to no luck by making use of "mechanize".

我很好奇,是否还有其他我可能不知道的解决方案会帮助我解决我的情况.如果以前在这里曾问过这个特定问题或一些相关的变体,请原谅,我更喜欢此特定查询的链接.否则,有什么常用的技术/方法来解决此问题?

I'm curious if there exist other solutions that I may be unaware of that would help me in my situation. If this particular question or some related variant has been asked here before, please excuse me, and I would prefer the link to this particular query. Otherwise, what are some common techniques/approaches for dealing with this issue?

谢谢.

推荐答案

我最近一直在使用 PhantomJS 用于此类工作-这是一个命令行工具,可让您在浏览器环境(基于Webkit)中运行Javascript.这使您可以进行需要启用Javascript的界面的抓取和在线交互.这里有一个基于Python的实现,它与C ++版本的API完全兼容,或者您​​可以通过subprocess在Python中运行任一版本.

I've recently been using PhantomJS for this kind of work - it's a command-line tool that allows you to run Javascript in a browser environment (based on Webkit). This allows you to do scraping and online interactions that require Javascript-enabled interfaces. There's a Python-based implementation here that's fully compatible with the API of the C++ version, or you could run either version in Python via subprocess.

根据您要执行的操作,另一个不错的选择可能是使用具有客户端驱动程序的 Selenium 在Python中实现-这是用于集成测试的,但是只要您可以运行基于Java的Selenium Server,并使自动化发生在开放的浏览器中,而不是作为后台进程,就可以执行很多自动化操作.

Depending on what you're trying to do, another good option might be to use Selenium, which has client driver implementation in Python - it's meant for integration testing, but can do a lot of automation as long as you're okay running the Java-based Selenium Server and having the automation happen in an open browser rather than as a background process.

这篇关于使用Python自动使用JavaScript表单登录网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆