python selenium简单介绍

一,介绍
Selenium是一个强大的开源Web功能测试工具系列,可进行读入测试套件、执行测试和记录测试结果,模拟真实用户操作,包括浏览页面、点击链接、输入文字、提交表单、触发鼠标事件等操作,并且能够对页面结果进行种种验证

二,环境准备
1,安装selenium
   可以使用pip install seleniu进行安装,这里演示用工具pycharm安装
   在PyCharm中file->setting,找到project->project interpreter,点击添加
  

在弹出的页面中

 2,驱动安装
   1.chromedriver的驱动下载地址:https://code.google.com/p/chromedriver/downloads/list
   2.Firefox的驱动geckodriver下载地址:https://github.com/mozilla/geckodriver/releases/
   下载解压到python目录即可
   
三、简单验证
http://m.credit100.com/#/redBlackList?type=3 这个页面是新华社重大税收违法案件当事人查询页面
查询具体某个企业新详情页面测试代码:

#-*- coding: UTF-8 -*-
import time
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from bs4 import BeautifulSoup as BS

compy_name='黑山县益盛药业有限公司'
compy_id='7693'
url="http://m.credit100.com/#/redBlackText?name="+compy_name+"&code="+compy_id+"&type=3"

# driver = webdriver.Chrome("D:/python36/chromedriver.exe")
#driver = webdriver.Firefox("D:\python36\geckodriver.exe")
driver = webdriver.Firefox()
driver.implicitly_wait(30)  # 等待
driver.get(url) # 访问地址
time.sleep(6)

# 公司
compy_Name_xpath = "/html/body/app-root/app-red-black-text/div/div/div/div/div/div[1]/div/h3"
#组织机构代码
org_xpath='/html/body/app-root/app-red-black-text/div/div/div/div/div/div[2]/ul/li[1]/h4'
#组织机构代码值
org_value_xpath='/html/body/app-root/app-red-black-text/div/div/div/div/div/div[2]/ul/li[1]/p'

compy_name = driver.find_element_by_xpath(compy_Name_xpath).text
org = driver.find_element_by_xpath(org_xpath).text
org_code = driver.find_element_by_xpath(org_value_xpath).text

#print
print(compy_name)
print(org)
print(org_code)

如果想详细看看具体的api,请参考https://selenium-python-zh.readthedocs.io/en/latest/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

朝闻道-夕死可矣

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值