使用请求登录有问题的站点 [英] Log in to a problematic site using requests

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

问题描述

我正在尝试使用请求模块在 python 中创建一个脚本来登录这个网站

I'm trying to create a script in python using requests module to log in to thissite

我正在使用我的凭据,但我找不到任何方法来这样做,因为我看不到随请求一起发送所需的参数(在 chrome 开发工具中).

I'm using my credentials but I don't find any way to do so as I can't see the parameters (in chrome dev tools) required to send along with requests.

username: SIMMTH.iqbal_123
password: SShift_123 

登录表单看起来像这个.

这是我最初的尝试(我真的在那个页面中找不到任何东西开始):

This is my initial attempt (I really could not find anything in that page to start with):

import requests
from bs4 import BeautifulSoup

link = "https://jobs.allianz.com/sap/bc/bsp/sap/zhcmx_erc_ui_ex/desktop.html#/SEARCH/RESULTS/"

with requests.Session() as s:
    s.headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36'
    r = s.get(link)
    print(r.text)

如何使用请求登录该站点?

How can I log in to that site using requests?

推荐答案

import requests
from bs4 import BeautifulSoup

with requests.Session() as req:
    r = req.get(
        "https://jobs.allianz.com/sap/hcmx/validate_ea?sap-client=100&sap-language={2}", auth=requests.auth.HTTPBasicAuth("SIMMTH.iqbal_123", "SShift_123"))
    r = req.get(
        "https://jobs.allianz.com/sap/opu/odata/hcmx/erc_ui_auth_srv/UserSet('me')?sap-client=100&sap-language=en")
    soup = BeautifulSoup(r.content, 'lxml')
    print(soup.prettify())

输出:

<?xml version="1.0" encoding="utf-8"?>
<html>
 <body>
  <entry xml:base="https://jobs.allianz.com/sap/opu/odata/hcmx/erc_ui_auth_srv/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
   <id>
    https://jobs.allianz.com/sap/opu/odata/hcmx/erc_ui_auth_srv/UserSet('SIMMTH.IQBAL_123') 
   </id>
   <title type="text">
    UserSet('SIMMTH.IQBAL_123')
   </title>
   <updated>
    2020-03-23T17:16:38Z
   </updated>
   <category scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" term="erc_ui_auth_srv.User">
   </category>
   <link href="UserSet('SIMMTH.IQBAL_123')" rel="edit" title="User"/>
   <link href="UserSet('SIMMTH.IQBAL_123')/DecimalFormat" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/DecimalFormat" title="DecimalFormat" type="application/atom+xml;type=entry"/>
   <link href="UserSet('SIMMTH.IQBAL_123')/DateFormat" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/DateFormat" title="DateFormat" type="application/atom+xml;type=entry"/>
   <link href="UserSet('SIMMTH.IQBAL_123')/Language" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Language" title="Language" type="application/atom+xml;type=entry"/>
   <link href="UserSet('SIMMTH.IQBAL_123')/$links/DecimalFormat" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/DecimalFormat" title="DecimalFormat" type="application/xml"/>
   <link href="UserSet('SIMMTH.IQBAL_123')/$links/DateFormat" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/DateFormat" title="DateFormat" type="application/xml"/>
   <link href="UserSet('SIMMTH.IQBAL_123')/$links/Language" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Language" title="Language" type="application/xml"/> 
   <content type="application/xml">
    <m:properties>
     <d:email>
      mthupwork@gmail.com
     </d:email>
     <d:firstname>
      shahin
     </d:firstname>
     <d:lastname>
      iqbal
     </d:lastname>
     <d:newpassword>
     </d:newpassword>
     <d:oldpassword>
     </d:oldpassword>
     <d:logonname>
      SIMMTH.IQBAL_123
     </d:logonname>
     <d:userid>
      SIMMTH.IQBAL_123
     </d:userid>
    </m:properties>
   </content>
  </entry>
 </body>
</html>

这篇关于使用请求登录有问题的站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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