【问题标题】:I need to open web page using Python我需要使用 Python 打开网页
【发布时间】:2020-07-30 03:40:02
【问题描述】:

我需要打开一个网站,登录它,然后在我的 Flask Web 服务器中显示打开的网页(一些 DIV)。

网站是https://home.solarman.cn/login.html

我尝试使用此代码进行登录

import requests

POSTLOGINURL = 'https://home.solarman.cn/login.html'

REQUESTURL = 'https://home.solarman.cn/main.html'


payload = {
    'username': '',
    'pass': ''
}

with requests.Session() as session:
    post = session.post(POSTLOGINURL, data=payload)
    r = session.get(REQUESTURL)
    print(r.text)

【问题讨论】:

  • ...和?发生了什么?这与 Flask 有什么关系?
  • @jonrsharpe 这就是 down-vote 发明的原因
  • 此代码与 Flask 无关。此代码仅用于登录
  • @SahakSahakyan 你还没有提到这里的问题是什么?
  • 这段代码没问题,我需要另一个代码来登录网站并在 Flask 网络服务器中显示它

标签: javascript python html python-requests


【解决方案1】:
import requests

target = "https://home.solarman.cn/main.html"

data = {
    "userName": "user@user.com",
    "userNameDisplay": "user@user.com",
    "password": "yourpass",
    "lan": "2",
    "domain": "home.solarman.cn",
    "userType": "C"
}


def main(url):
    with requests.Session() as req:
        r = req.post(url, data=data).json()
        print(r)
        r = req.get(target)
        print(r)


main("https://home.solarman.cn/cpro/login/validateLogin.json")

【讨论】:

  • 我需要在 Flask Web 服务器中显示网页,例如使用
  • 我看到英语是这个问题的主要问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-28
  • 1970-01-01
相关资源
最近更新 更多