【问题标题】:How to call Javascript function in Python (web-crawler)?如何在 Python(网络爬虫)中调用 Javascript 函数?
【发布时间】:2019-01-22 08:06:26
【问题描述】:

HTML 登录按钮:<a href="javascript:loginSendit(document.login_form);" tabindex="3"></a>

HTML 用户 ID:<input name="userid" type="text" tabindex="1" class="login_input" value="" onfocus="check_userid_on()" onclick="check_userid_on()" onblur="check_userid_off()">

我附上了user_id、user_pw和登录按钮页面源的图片,以便更好地理解。

https://i.stack.imgur.com/kr8Nf.png
https://i.stack.imgur.com/irZJz.png

在 python 中,我想插入 user_id 和 user_pw 然后使用登录按钮登录,该登录按钮有一个名为 loginsendit() 的 javascript 函数

到目前为止,我的代码开始像

LOGIN_INFO = {
'userId': 'myidid',
'userPassword': 'mypassword123'

}

user_id = soup.find('input' , {'name': 'userid'})
user_id['value'] = LOGIN_INFO['userid']

user_pw = soup.find('input', {'name': 'userpw'})
user_pw['value'] = LOGIN_INFO['userPassword']


login_req = s.post('url', data='loginSendit()')
print(login_req.status_code)

但即使密码或用户名错误,它也只会打印出 200,这意味着我的代码不允许我登录。

你能帮我如何在 Python 中调用这个 loginsendit() javascript 函数吗?

【问题讨论】:

    标签: python web-crawler


    【解决方案1】:

    如果您想执行 JavaScript,请查找 phantomjs - general tutorial,线程:Running javascript in Selenium using PythonExecuting Javascript on Selenium/PhantomJS

    【讨论】:

    • 有没有办法从网页源调用javascript函数并在python中使用相同的函数?而不是使用 phantomJS
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-12
    • 1970-01-01
    • 2011-04-15
    相关资源
    最近更新 更多