模拟登录(python)
Posted 是璇子鸭
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了模拟登录(python)相关的知识,希望对你有一定的参考价值。
模拟登陆
from selenium import webdriver #导入webdriver
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.common.action_chains import ActionChains
driver_path = "chromedriver.exe" #指定浏览器驱动
driver = webdriver.Chrome(executable_path=driver_path) #实例化一个机器人对象
driver.get('目标网站地址')
actions = ActionChains(driver)
#账号输入框
usernameTag = driver.find_element_by_xpath('相应xpath')
#密码框
passwordTag = driver.find_element_by_xpath('')
#登录按钮
submitTag = driver.find_element_by_xpath('')
actions = ActionChains(driver)
#输入
actions.move_to_element(usernameTag)
actions.send_keys_to_element(usernameTag, '用户名')
actions.move_to_element(passwordTag)
actions.send_keys_to_element(passwordTag, '密码')
actions.move_to_element(submitTag)
actions.click(submitTag)
actions.perform()
ip代理
- 芝麻代理
- 快代理
- 多贝ip代理
from selenium import webdriver #导入webdriver
options = webdriver.ChromeOptions()
options.add_argument('- -headless')
options.add_argument('--disable-gpu')
driver_path = 'chromedriver.exe'
driver = webdriver.Chrome(executable_path = driver_path, options=options)
driver.get('http://httpbin.org/ip')
print(driver.page_source)
获取截图及标签属性值
from selenium import webdriver #导入webdriver
options = webdriver.ChromeOptions()
options.add_argument('- -headless')
options.add_argument('--disable-gpu')
driver_path = 'chromedriver.exe'
driver = webdriver.Chrome(executable_path = driver_path, options=options)
driver.get('http://www.baidu.com')
submitBtn = driver.find_element_by_id('su')
print(submitBtn.get_attribute('value'))
driver.set_window_size(800,900)
driver.save_screenshot('baidu.png') #网页截图
#print(driver.page_source)
以上是关于模拟登录(python)的主要内容,如果未能解决你的问题,请参考以下文章
python http requests 怎么实现模拟登录,提交表单