使用onclick按钮登录网站进行提交

2024-09-27 21:28:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用python3.7进行web抓取a website,需要用户的电子邮件和密码才能登录

登录页面的登录形式如下:

  <div id="login">
<form action="/account/orthodox_login" method="post" id="orthodox_login">
  <input id="slugs_input_login" name="slugs[]" type="hidden" value="" />
  <input id="return_after_login" name="rt" type="hidden" value="" />
  <input name="user[url_source]" type="hidden" value="" id="login_form_url_source" />
  <input name="user[location_source]" type="hidden" value="orthodox_login" />

  <h1 id="member_h1">Member sign in</h1>

  <div id="notice_login" class="notice_message" style="margin-top: 20px"></div>

  <div id="with_email" class="fwb login_update" style="display: none; margin-bottom: 0; font-size: 13px; color: #484848;">Sign in with email:</div>

  <fieldset>
    <span>Email:</span>
    <input name="user[email]" id="login_user_email" type="email" autocorrect="off" autocapitalize="off" spellcheck="false" />
  </fieldset>


  <fieldset>
    <span>Password:</span>
    <div id='password_wrapper'><input name="user[password]" type="password" id="login_user_password" autocorrect="off" autocapitalize="off" /></div>
  </fieldset>


      <div class="register_button" onclick="submit_orthodox_login_form();">
        <span class="l"></span>
        <input class="c" type="button" value="Sign in" />
        <span class="r"></span>
      </div>
    </form>


      <div id="or_google" class="fwb mb7 login_update" style="display: none; width: 250px; font-size: 13px; color: #484848;">Or sign in with Google:</div>
  <div id="another_place" class="login_update" style="display: none; margin-left: -10px;"></div>
  <div class="secret_line login_update" style="display: none; margin-bottom: 16px">
    <div style="border-bottom: 1px solid #ebebeb; width: 313px; margin-bottom: 0;"></div>
  </div>
  <div id="dont_have" class="roy-gray login_update" style="display: none">Don't have an account? <span class="link" onclick="open_header_log_in_popup_lightbox('headtabs_login',''); return false">Join now</span></div>
  </div>

我搜索了其他关于登录的帖子,答案是使用mechanicalsoup给出的:

br = mechanicalsoup.StatefulBrowser(
    soup_config={'features': 'lxml'},
    raise_on_404=True,
    user_agent='MyBot/0.1: mysite.example.com/bot_info',
)

br.open("https://seekingalpha.com/account/login")
br.select_form('#orthodox_login')


browser["login"] = args.username
browser["password"] = args.password
resp = browser.submit_selected()

然而,这在我的例子中不起作用,因为在表单中没有像在github's login中那样的<input type="submit">,而是一个<div class="register_button" onclick="submit_orthodox_login_form();">

我还想在登录后重定向到this link,这是我想删除的实际网站


Tags: nameindivformidinputvaluestyle
1条回答
网友
1楼 · 发布于 2024-09-27 21:28:22

我认为您想要自动化的网站使用JavaScript,而MechanicalSoup不支持JavaScript。 您应该寻找像selenium这样支持javascript的解决方案

相关问题 更多 >

    热门问题