带有验证令牌的Python发布请求

时间:2020-02-19 18:29:16

标签: python web-scraping python-requests

我查看了关于stackoverflow的许多其他回复,并观看了一些冗长的youtube视频,但仍未迷惑能为我的问题提供解决方案的信息。我曾在其他实例中使用post登录和抓取,只是没有请求令牌时才使用。也许有人可以看看?我将在图片中包含post参数。应该注意的是,每次我登录时,__RequestVerificationToken都会更改。

import requests

payload = {
'Email': 'dfo.msdi-idsm.mpo@dfo-mpo.gc.ca',
'Password': 'notrealpassword',
'__RequestVerificationToken': 'RuOal6rKBCWdjNy_15nTS9duFSkM586yGD3LxlWrlGzBB3Noaha9hAm3-tMq9HPvvMstDL8BZ8PvQLPutsreSeGwQOzK1MMwl76Q2c7n1zo1',
}

URL = 'http://gisd.dfo-mpo.gc.ca/DFO_WebServiceManager/Account/Login'
Pacific = 'https://gisd.dfo-mpo.gc.ca/DFO_WebServiceManager/FGP?SearchString=Pacific'

with requests.session() as c:
    c.post(URL, data=payload)
    r = c.get(Pacific)
    print r.content

enter image description here

1 个答案:

答案 0 :(得分:0)

该令牌看起来像CSRF令牌。您应该将包含<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name = "Tshirt"> <xs:complexType> <xs:sequence> <xs:element name = "Color" type = "clothesColorType" /> <xs:element name = "Size" type = "clothesSizeType" /> </xs:sequence> </xs:complexType> </xs:element> <xs:simpleType name="clothesSizeType"> <xs:restriction base="xs:string"> <xs:enumeration value="S" /> <xs:enumeration value="M" /> <xs:enumeration value="L" /> <xs:enumeration value="XL" /> </xs:restriction> </xs:simpleType> <xs:simpleType name="clothesColorType"> <xs:restriction base="xs:string"> <xs:enumeration value="Black" /> <xs:enumeration value="White" /> <xs:enumeration value="Green" /> <xs:enumeration value="Blue" /> </xs:restriction> </xs:simpleType> </xs:schema> 的cookie添加到请求中,并查看其是否有效。

org.xml.sax.SAXParseException; systemId: file:/ruta/src/main/resources/wsdl-definition/Assurance.xsd; lineNumber: 47; columnNumber: 72; src-resolve: No se puede resolver el nombre 'clothesColorType' para un componente 'type definition'.