登录按钮即可进行Python网络抓取

时间:2020-03-19 14:59:38

标签: python authentication web-scraping python-requests

不幸的是,我离Frontend很远,以前我只抓取具有直接链接的简单站点。但是在这里,我遇到了一些JavaScript React Modal魔术,无法理解如何突破登录页面。

因此,我正在尝试连接到https://megamarket.zakaz.ua/en/。单击“登录”时,会弹出一个登录窗口。

我的计划是使用登录选项发出POST请求,然后使用BeautifulSoup进行解析。

类似这样的东西:

with requests.Session() as s:
    s.post('https://megamarket.zakaz.ua/en/login', data = {
        'username': <logn>,
        'password': <pass>}
        )
    data = s.get(...parse link...)
# btfsp on data

但是我没有检查元素-无法弄清楚如何使用所有这些现代的可视弹出元素发出POST请求。我想我需要使用Selenium lib。

我们非常感谢您的帮助。

enter image description here

由于@Kurosh,我设法为POST请求获取正确的数据,但不知何故获得了状态400 {"errors":[{"error_code":4182,"description":"Login or password is incorrect."}]}

import requests
payload={"login": "38063333333", "password": "275699"}
url = "https://stores-api.zakaz.ua/user/login/"
with requests.Session() as s:
    response_op = s.post(url, json=payload)
    print(response_op.status_code)
    print(response_op.text)

数据正确: enter image description here

好的。这是我的错-completley忘记了Request中的Headers。 现在一切都很好!

enter image description here

0 个答案:

没有答案