无法使用请求在网页中保存表单的某些字段

2024-05-15 19:54:32 发布

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

我已经用python创建了一个脚本,使用requests模块分别使用名称和密码SIMMTH.iqbal_123SShift_123登录到这个site。我现在想做的是在填写相应的表格后保存一份申请表。但是,登录后,当您浏览此link时,您将看到表单。这就是form的样子(我手动填写并保存的字段)

到目前为止,我已经尝试过:

import requests
from bs4 import BeautifulSoup

link = 'https://jobs.allianz.com/sap/bc/bsp/sap/zhcmx_erc_ui_ex/desktop.html#/APPLICATION/57259884'
post_url = 'https://jobs.allianz.com/sap/opu/odata/hcmx/erc_ui_auth_srv/ProfileSet?sap-client=100&sap-language=en'

payload = {"ProfileID":1,"Firstname":"taher","Lastname":"iqbal","Address1":"","Address2":"","City":"","PostalCode":"","Email":"mthupwork@gmail.com","Phone1":"","Phone2":"01790127774","HasAcceptedPrivStmt":True,"IsLocked":True,"ThumbnailUrl":"","PhotoUrl":"","Phone3":"","PrefDescription":"","PrefWillingessRelocate":None,"PrefWillingnessTravel":None,"PrefIndustrySet":[],"PrefLocationSet":[],"PrefHierarchyLevelSet":[],"PrefFunctionalAreaSet":[],"Salutation":2,"Country":{"CountryID":"BD"}}

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'
    s.auth = ("SIMMTH.iqbal_123", "SShift_123")

    s.get("https://jobs.allianz.com/sap/hcmx/validate_ea?sap-client=100&sap-language={2}")
    s.get("https://jobs.allianz.com/sap/opu/odata/hcmx/erc_ui_auth_srv/UserSet('me')?sap-client=100&sap-language=en")

    res = s.post(post_url,json=payload,headers={
        'Content-Type': 'application/json;odata=verbose',
        'Referer': 'https://jobs.allianz.com/sap/bc/bsp/sap/zhcmx_erc_ui_ex/desktop.html'
    })
    print(res.status_code)

我对上面的payload的值进行了一些更改,以便检查脚本是否能够修改表单。但是,当我执行脚本时,它会给我403状态代码

How can I save the fields of the form in that webpage using requests?

顺便说一句,this是我以前的帖子


Tags: https脚本comclientauthuijobspost
1条回答
网友
1楼 · 发布于 2024-05-15 19:54:32
import requests
from bs4 import BeautifulSoup

json = {"ProfileID": 1, "Firstname": "shahin", "Lastname": "iqbal", "Address1": "", "Address2": "", "City": "dhaka", "PostalCode": "1216", "Email": "someemail@gmail.com", "Phone1": "", "Phone2": "01790129994", "HasAcceptedPrivStmt": True, "IsLocked": True, "ThumbnailUrl": "",
        "PhotoUrl": "", "Phone3": "", "PrefDescription": "", "PrefWillingessRelocate": None, "PrefWillingnessTravel": None, "PrefIndustrySet": [], "PrefLocationSet": [], "PrefHierarchyLevelSet": [], "PrefFunctionalAreaSet": [], "Salutation": 2, "Country": {"CountryID": "BD"}}

headers = {'x-csrf-token': 'Fetch'}


def Login():
    with requests.Session() as req:
        r = req.post(
            "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", headers=headers)
        token = r.headers.get("x-csrf-token")
        headers["x-csrf-token"] = token
        r = req.post(
            "https://jobs.allianz.com/sap/opu/odata/hcmx/erc_ui_auth_srv/ProfileSet?sap-client=100&sap-language=en", json=json, headers=headers)
        soup = BeautifulSoup(r.content, 'lxml')
        print(soup.prettify())


Login()

输出:

<?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/ProfileSet(1)
   </id>
   <title type="text">
    ProfileSet(1)
   </title>
   <updated>
    2020-03-24T07:08:15Z
   </updated>
   <category scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" term="erc_ui_auth_srv.Profile">
   </category>
   <link href="ProfileSet(1)" rel="edit" title="Profile"/>
   <link href="ProfileSet(1)/Country" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Country" title="Country" type="application/atom+xml;type=entry"/>
   <m:inline>
   </m:inline>
   <link href="ProfileSet(1)/Region" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Region" title="Region" type="application/atom+xml;type=entry"/>
   <link href="ProfileSet(1)/JobAgentSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/JobAgentSet" title="JobAgentSet" type="application/atom+xml;type=feed"/>   
   <link href="ProfileSet(1)/PrefLocationSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/PrefLocationSet" title="PrefLocationSet" type="application/atom+xml;type=feed"/>
   <m:inline>
   </m:inline>
   <link href="ProfileSet(1)/JobBookmarkSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/JobBookmarkSet" title="JobBookmarkSet" type="application/atom+xml;type=feed"/>
   <link href="ProfileSet(1)/AttachmentSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/AttachmentSet" title="AttachmentSet" type="application/atom+xml;type=feed"/>
   <link href="ProfileSet(1)/PrefHierarchyLevelSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/PrefHierarchyLevelSet" title="PrefHierarchyLevelSet" type="application/atom+xml;type=feed"/>
   <m:inline>
   </m:inline>
   <link href="ProfileSet(1)/PrefFunctionalAreaSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/PrefFunctionalAreaSet" title="PrefFunctionalAreaSet" type="application/atom+xml;type=feed"/>
   <m:inline>
   </m:inline>
   <link href="ProfileSet(1)/PrefContractType" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/PrefContractType" title="PrefContractType" type="application/atom+xml;type=entry"/>
   <link href="ProfileSet(1)/PrefIndustrySet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/PrefIndustrySet" title="PrefIndustrySet" type="application/atom+xml;type=feed"/>
   <m:inline>
   </m:inline>
   <link href="ProfileSet(1)/PrefSalaryRange" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/PrefSalaryRange" title="PrefSalaryRange" type="application/atom+xml;type=entry"/>
   <link href="ProfileSet(1)/PrefInterestGroup" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/PrefInterestGroup" title="PrefInterestGroup" type="application/atom+xml;type=entry"/>
   <link href="ProfileSet(1)/InternetReferenceSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/InternetReferenceSet" title="InternetReferenceSet" type="application/atom+xml;type=feed"/>
   <link href="ProfileSet(1)/FtQualificationSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FtQualificationSet" title="FtQualificationSet" type="application/atom+xml;type=feed"/>
   <link href="ProfileSet(1)/ScQualificationSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ScQualificationSet" title="ScQualificationSet" type="application/atom+xml;type=feed"/>
   <link href="ProfileSet(1)/WorkExperienceSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/WorkExperienceSet" title="WorkExperienceSet" type="application/atom+xml;type=feed"/>
   <link href="ProfileSet(1)/EducationSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/EducationSet" title="EducationSet" type="application/atom+xml;type=feed"/>
   <link href="ProfileSet(1)/ApplicationSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ApplicationSet" title="ApplicationSet" type="application/atom+xml;type=feed"/>
   <link href="ProfileSet(1)/$links/Country" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Country" title="Country" type="application/xml"/>
   <link href="ProfileSet(1)/$links/Region" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Region" title="Region" type="application/xml"/>
   <link href="ProfileSet(1)/$links/JobAgentSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/JobAgentSet" title="JobAgentSet" type="application/xml"/>      
   <link href="ProfileSet(1)/$links/PrefLocationSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/PrefLocationSet" title="PrefLocationSet" type="application/xml"/>
   <link href="ProfileSet(1)/$links/JobBookmarkSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/JobBookmarkSet" title="JobBookmarkSet" type="application/xml"/>
   <link href="ProfileSet(1)/$links/AttachmentSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/AttachmentSet" title="AttachmentSet" type="application/xml"/>
   <link href="ProfileSet(1)/$links/PrefHierarchyLevelSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/PrefHierarchyLevelSet" title="PrefHierarchyLevelSet" 
type="application/xml"/>
   <link href="ProfileSet(1)/$links/PrefFunctionalAreaSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/PrefFunctionalAreaSet" title="PrefFunctionalAreaSet" 
type="application/xml"/>
   <link href="ProfileSet(1)/$links/PrefContractType" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/PrefContractType" title="PrefContractType" type="application/xml"/>
   <link href="ProfileSet(1)/$links/PrefIndustrySet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/PrefIndustrySet" title="PrefIndustrySet" type="application/xml"/>
   <link href="ProfileSet(1)/$links/PrefSalaryRange" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/PrefSalaryRange" title="PrefSalaryRange" type="application/xml"/>
   <link href="ProfileSet(1)/$links/PrefInterestGroup" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/PrefInterestGroup" title="PrefInterestGroup" type="application/xml"/>
   <link href="ProfileSet(1)/$links/InternetReferenceSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/InternetReferenceSet" title="InternetReferenceSet" type="application/xml"/>
   <link href="ProfileSet(1)/$links/FtQualificationSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/FtQualificationSet" title="FtQualificationSet" type="application/xml"/>
   <link href="ProfileSet(1)/$links/ScQualificationSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/ScQualificationSet" title="ScQualificationSet" type="application/xml"/>
   <link href="ProfileSet(1)/$links/WorkExperienceSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/WorkExperienceSet" title="WorkExperienceSet" type="application/xml"/>
   <link href="ProfileSet(1)/$links/EducationSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/EducationSet" title="EducationSet" type="application/xml"/>   
   <link href="ProfileSet(1)/$links/ApplicationSet" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/ApplicationSet" title="ApplicationSet" type="application/xml"/>
   <content type="application/xml">
    <m:properties>
     <d:salutation>
      2
     </d:salutation>
     <d:thumbnailurl>
     </d:thumbnailurl>
     <d:photourl>
     </d:photourl>
     <d:prefdescription>
     </d:prefdescription>
     <d:prefwillingessrelocate>
      0
     </d:prefwillingessrelocate>
     <d:prefwillingnesstravel>
      0
     </d:prefwillingnesstravel>
     <d:prefemploymentfraction>
      0
     </d:prefemploymentfraction>
     <d:hasacceptedprivstmt>
      true
     </d:hasacceptedprivstmt>
     <d:islocked>
      true
     </d:islocked>
     <d:postalcode>
      1216
     </d:postalcode>
     <d:lastname>
      iqbal
     </d:lastname>
     <d:firstname>
      shahin
     </d:firstname>
     <d:email>
      someemail@gmail.com
     </d:email>
     <d:city>
      dhaka
     </d:city>
     <d:phone3>
     </d:phone3>
     <d:phone2>
      01790129994
     </d:phone2>
     <d:phone1>
     </d:phone1>
     <d:address2>
     </d:address2>
     <d:address1>
     </d:address1>
     <d:profileid>
      1
     </d:profileid>
    </m:properties>
   </content>
  </entry>
 </body>
</html>

相关问题 更多 >