【发布时间】:2021-10-29 18:19:44
【问题描述】:
所以基本上我试图在这个页面上登录微软:https://login.live.com/
使用 selenium,因为请求是针对更基本的身份验证页面。这是我的硒代码
email = 'password'
password = 'password'
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium import webdriver
from selenium.webdriver.common.by import By
EMAILFIELD = (By.ID, "i0116")
PASSWORDFIELD = (By.ID, "i0118")
NEXTBUTTON = (By.ID, "idSIButton9")
browser = webdriver.Chrome()
browser.get('https://login.live.com')
WebDriverWait(browser, 10).until(EC.element_to_be_clickable(EMAILFIELD)).send_keys(email)
WebDriverWait(browser, 10).until(EC.element_to_be_clickable(NEXTBUTTON)).click()
WebDriverWait(browser, 10).until(EC.element_to_be_clickable(PASSWORDFIELD)).send_keys(password)
WebDriverWait(browser, 10).until(EC.element_to_be_clickable(NEXTBUTTON)).click()
WebDriverWait(browser, 10).until(EC.element_to_be_clickable(NEXTBUTTON)).click()
然后我想在认证后使用请求打印出页面。这是我的请求代码:
from bs4 import BeautifulSoup
import requests
req = requests.get("https://account.microsoft.com/?lang=en-US&refd=account.live.com&refp=landing&mkt=EN-US")
soup = BeautifulSoup(req.text, 'html.parser')
print(soup.title)
print(req)
预期结果是此页面的 html 标题:https://account.microsoft.com/?lang=en-US&refd=account.live.com&refp=landing&mkt=EN-US(Microsoft 帐户 | 主页)
<title>Microsoft account | Home</title>
<Response [200]>
但我得到的输出是
<title>Microsoft account | Sign In or Create Your Account Today – Microsoft</title>
<Response [200]>
这是这个页面:https://account.microsoft.com/account(Microsoft 帐户 | 立即登录或创建您的帐户 - Microsoft)
请帮助我,提前谢谢你!
【问题讨论】:
-
req正在返回什么,你能分享一下它的状态码吗 -
-
您是否尝试使用 selenium 打印标题?我看到您在请求模块的情况下有不同的终点
-
不,但我想知道是否可以使用请求。对我来说更容易。如果需要的话,我会一直使用硒
标签: python selenium beautifulsoup python-requests web-crawler