前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python 3 的selenium模块

python 3 的selenium模块

作者头像
py3study
发布2020-01-06 14:16:36
4760
发布2020-01-06 14:16:36
举报
文章被收录于专栏:python3python3

基于python 3 的selenium模块实现网页自动登陆

----http://blog.csdn.net/u010637662/article/details/53612197

[Python爬虫] Selenium实现自动登录163邮箱和Locating Elements介绍 ----http://blog.csdn.net/eastmount/article/details/47825633

selenium之 chromedriver与chrome版本映射表(更新至v2.30) ----http://blog.csdn.net/huilan_same/article/details/51896672

[Python爬虫] Selenium自动访问Firefox和Chrome并实现搜索截图

----http://blog.csdn.net/eastmount/article/details/47799865

python-selenium-firefox环境搭建时常遇到的小问题

----http://www.cnblogs.com/Jindy-mine/p/6430000.html

firefox 报错“os.path.basename(self.path), self.start_error_message)

selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH”的解决办法:

1. selenium 3.x开始,webdriver/firefox/webdriver.py的__init__中,executable_path="geckodriver";而2.x是executable_path="wires" 2. firefox 47以上版本,需要下载第三方driver,即geckodriver;在http://docs.seleniumhq.org/download/的Third Party Drivers, Bindings, and Plugins下面找到Mozilla GeckoDriver,下载到任意电脑任意目录,解压后将该路径加入到PC的path(针对windows)即可。

示例:

代码语言:javascript
复制
#!/usr/bin/python
# -*- coding: utf-8 -*-


import time
import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
  
chromedriver = "C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe"
os.environ["webdriver.chrome.driver"] = chromedriver
  
driver = webdriver.Chrome(chromedriver)
driver.get("http://172.16.77.160:8080/")
assert "XORMEDIA" in driver.title  
user = driver.find_element_by_name("user_id")
user.send_keys("su")
elem_pwd = driver.find_element_by_name("password")
elem_pwd.send_keys("su")
elem_pwd.send_keys(Keys.RETURN)
try:
    if driver.find_element_by_id('_PM'):
        driver.find_element_by_id('_PM').click()
except:
    print('can not find PM')
try:
    if driver.find_element_by_xpath('//*[@id="_label"]/tbody/tr[3]/td/a/img'):
        driver.find_element_by_xpath('//*[@id="_label"]/tbody/tr[3]/td/a/img').click()
except:
    print('can not enter PM')

driver.switch_to_frame('left')
driver.switch_to_frame('leftMainFrame')
try:
    if driver.find_element_by_xpath('/html/body/form/table[1]/tbody/tr[3]/td/a'):
        driver.find_element_by_xpath('/html/body/form/table[1]/tbody/tr[3]/td/a').click()
except:
    print('can not open 电子节目单列表')
print(driver.find_element_by_xpath('/html/body/form/table[1]/tbody/tr[3]/td/a').text)
driver.switch_to_default_content()
driver.switch_to_frame('frameb')
driver.switch_to_frame('mainFrame_b')
try:
    if driver.find_element_by_xpath('//*[@id="objSearchCondition"]/tbody/tr[1]/td[2]/select/option[18]'):
        driver.find_element_by_xpath('//*[@id="objSearchCondition"]/tbody/tr[1]/td[2]/select/option[18]').click()
except:
    print('can not open CCTV1')
driver.find_element_by_xpath('//*[@id="objSearchCondition"]/tbody/tr[1]/td[4]/a').click()    
       
assert "test" in driver.title   
driver.close()  
driver.quit()
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-09-23 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档