python - 无法使用请求在网页中保存表单的某些字段
问题描述
我在 python 中创建了一个脚本,使用 requests 模块分别使用名称和密码登录该站点SIMMTH.iqbal_123
,并且SShift_123
. 我现在想做的是在相应填写后保存申请表。但是,登录后,当您浏览此链接时,您将看到表单。这就是表单的样子(我手动填写并保存的字段)。
到目前为止我已经尝试过:
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
状态码。
如何使用请求将表单的字段保存在该网页中?
顺便说一句,这是我之前的帖子。
解决方案
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>
推荐阅读
- r - 带传单/ R的时间滑块
- javascript - 如何从 iOS cordova 插件调用 ionic 1 方法
- episerver - 更改语言时,episerver 预览通过 http 而不是 https 加载
- python - 阶乘数字和拼图,时间复杂度调查
- java - 在 Spring 启动测试中,我如何创建一个 bean 并通过 @Autowired 注入?
- ros - ModuleNotFoundError:没有名为“std_msgs”的模块 - Gazebo 安装
- r - 在 R 中使用 ggplot 绘制多个值与时间的折线图
- swift - Swift - 只要应用程序正在运行,我如何将对象存储在缓存中?- NSCache() 会在其他 vc 显示后立即被清除
- c# - Bot 中的 MS Bot c# Custom Vision 预测端点错误“不支持给定路径的格式。”
- windows - 使用 jenkins 管道检查代码并在任何可用的节点/代理上构建它