没有重定向到它应该重定向到的位置

没有重定向到它应该重定向到的位置

本文介绍了Mechanicalsoup 没有重定向到它应该重定向到的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个登录到 https://adelbert.magister.net/ 这样我就可以在登录后抓取网站中的数据.

I am trying to make a webscraping bot that logs into https://adelbert.magister.net/ so that I can scrap data in the website after logging in.

我的代码:

import mechanicalsoup
browser = mechanicalsoup.StatefulBrowser(
    soup_config={'features': 'lxml'},
    raise_on_404=True,
    user_agent='bot',
)

browser.open("https://adelbert.magister.net/")
print(browser.get_url())

如果您在普通浏览器中访问该页面,它会重定向到如下所示的 URL: HTTPS://accounts.magister.net/account/login?sessionId=6aa0c7f9387a4b4b8acea413446d918c&returnUrl=%2Fconnect%2Fauthorize%2Fcallback%3Fclient_id%3DM6-adelbert.magister.net%26redirect%2A52F1%2F152F100000000000000000000000252Fredirect_callback.html%26response_type%3Did_token%2520token%26scope%3Dopenid%2520profile%2520magister.ecs.legacy%2520magister.mdv.broker.read%2520magister.dnn.roles.read%26state%3D505f79f6dc244b8ba45daaa215709ac0%26nonce%3D49d332e1fb2e499fb2a17bcd37d756a4%26acr_values%3Dtenant%253Aadelbert.magister.net#!/gebruikersnaam

If you visit the page in your normal browser it redirects to a URL that looks like this: https://accounts.magister.net/account/login?sessionId=6aa0c7f9387a4b4b8acea413446d918c&returnUrl=%2Fconnect%2Fauthorize%2Fcallback%3Fclient_id%3DM6-adelbert.magister.net%26redirect_uri%3Dhttps%253A%252F%252Fadelbert.magister.net%252Foidc%252Fredirect_callback.html%26response_type%3Did_token%2520token%26scope%3Dopenid%2520profile%2520magister.ecs.legacy%2520magister.mdv.broker.read%2520magister.dnn.roles.read%26state%3D505f79f6dc244b8ba45daaa215709ac0%26nonce%3D49d332e1fb2e499fb2a17bcd37d756a4%26acr_values%3Dtenant%253Aadelbert.magister.net#!/gebruikersnaam

如何在好的页面上获取,以便用mechanicalsoup进行程序登录?

How can I get it on the good page so that I can make the program login with mechanicalsoup?

这与此处发布的问题相同,但没有人回答该帖子.请帮帮我.

This is the same question as posted Here but no one has answered that post. Please help me.

推荐答案

重定向是使用 JavaScript 完成的.MechanicalSoup 对 JavaScript 没有帮助(请参阅 MechanicalSoup 的 常见问题解答).

The redirect is done using JavaScript. MechanicalSoup won't help with JavaScript (see MechanicalSoup's FAQ).

这篇关于Mechanicalsoup 没有重定向到它应该重定向到的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 06:17