如何抓取一个使用Python (BeautifulSoap,Requests)登录的BankID网站?
我想用BankID登录,然后用python创建一个网站。如何登录到使用BankID登录的网站?
常规方法不起作用:
from bs4 import BeautifulSoup
import requests
source = requests.get('https://example.com').text
soup = BeautifulSoup(source, 'lxml')
print(soup)发布于 2020-10-04 20:16:32
最好的方法是使用selenium。下面是使用selenium的方法:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
driver = webdriver.Chrome() #Opens the chromedriver. If u don't have a chromedriver, u can download it from https://chromedriver.chromium.org/downloads
driver.get('Url of the banking website') #Opens the specified url
bank_id = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, 'Textbox xpath'))) #Finds the bank_id textbox
bank_id.click() #Clicks it
bank_id.send_keys('Your username') #Enters ur username in the textbox
pswrd = driver.find_element_by_xpath('Xpath of textbox') #Does the same for the password.
pswrd.click()
pswrd.send_keys('Your password')
login_btn = driver.find_element_by_xpath('Xpath of submit button') #Finds the login button
login_btn.click() #Clicks the login button就这样!您已登录网站!希望这能对你有所帮助!
https://stackoverflow.com/questions/64194425
复制相似问题