0

Problem

I'm trying to use mechanicalsoup to login to ORCID, but I'm unable to access the login form.

Attempts

This should be very straightforward:

import mechanicalsoup

browser = mechanicalsoup.StatefulBrowser()
browser.open('https://orcid.org/signin')
browser.select_form('form[id="loginForm"]')

However, this results in a LinkNotFoundError.

I also tried simply finding any form with a non-stateful browser:

import mechanicalsoup

browser = mechanicalsoup.Browser()
login_page = browser.get('https://orcid.org/signin')
print(login_page.soup.find_all('form'))

And that yields an empty list, so it's not even seeing the form in the return. This confused me, as print(login_page.soup) returns everything, and I could see the form in there.

Question

How can I access the form and successfully login? (I'm fully open to using something other than mechanicalsoup, too.)

I imagine it has something to do with the fact that you can switch login methods on the page itself. See here:

orcid login page image

I'm very far from a frontend expert, but when I inspect the page, I imagine that's governed in some way by the events seen here:

orcid login page inspector image

If anyone can provide any help or insight, I'd certainly appreciate it. Thank you!

4

1 回答 1

2

虽然https://orcid.org/signin上的登录表单似乎是一个不需要 JavaScript 的简单表单,但生成登录页面本身却可以

您可以通过在禁用 JavaScript 的情况下访问浏览器中的登录页面来测试这一点(例如,请参阅Chrome 的说明)。执行此操作时,我会看到一个空白页面,其中包含以下消息:

要使用本网站的全部功能,必须启用 JavaScript。以下是在 Web 浏览器中启用 JavaScript 的说明。

不幸的是,MechanicalSoup 似乎无法在这里为您提供帮助,因为它不支持 JavaScript。您可能需要尝试像 Selenium 这样成熟的浏览器模拟器。

于 2020-02-26T22:12:39.623 回答