如何抓取使用BankID进行Python登录的网站(BeautifulSoap,请求)?
我想使用BankID登录,然后使用python抓取一个网站。您如何登录到使用BankID登录的网站?
常规行不通:
from bs4 import BeautifulSoup
import requests
source = requests.get('https://example.com').text
soup = BeautifulSoup(source, 'lxml')
print(soup)
答案 0 :(得分:1)
最好的方法是使用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
就是这样!您已登录网站!希望这会有所帮助!