首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何抓取一个使用Python (BeautifulSoap,Requests)登录的BankID网站?

如何抓取一个使用Python (BeautifulSoap,Requests)登录的BankID网站?
EN

Stack Overflow用户
提问于 2020-10-04 20:09:34
回答 1查看 157关注 0票数 0

如何抓取一个使用Python (BeautifulSoap,Requests)登录的BankID网站?

我想用BankID登录,然后用python创建一个网站。如何登录到使用BankID登录的网站?

常规方法不起作用:

代码语言:javascript
复制
from bs4 import BeautifulSoup

import requests

source = requests.get('https://example.com').text

soup = BeautifulSoup(source, 'lxml')

print(soup)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-04 20:16:32

最好的方法是使用selenium。下面是使用selenium的方法:

代码语言:javascript
复制
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

就这样!您已登录网站!希望这能对你有所帮助!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64194425

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档