控制已打开的浏览器

https://www.cnblogs.com/lovealways/p/9813059.html

selenium、自动填充文本框、自动点按钮

https://blog.csdn.net/github_26672553/article/details/78579038

selenium driver  驱动器下载:

http://npm.taobao.org/mirrors/chromedriver/

获取标签属性值

https://www.linuxhub.org/?p=3801

  1. from openpyxl import load_workbook
  2. from selenium import webdriver
  3. from selenium.webdriver.chrome.options import Options
  4. from openpyxl.utils import get_column_letter
  5. import time
  6.  
  7. chrome_options = Options()
  8. chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
  9. chrome_driver = "D:\Program Files\Python36\Scripts\chromedriver.exe"
  10. driver = webdriver.Chrome(chrome_driver, chrome_options=chrome_options)
  11.  
  12. driver.get('http://search.anccnet.com/searchResult2.aspx')
  13. wb = load_workbook(r'C:\Users\admin\Desktop\T1.xlsx')
  14. sheet = wb.get_sheet_by_name('Sheet1')
  15.  
  16. for cell in list(sheet.columns)[0]:
  17. try:
  18. searchInput = driver.find_element_by_id('keyword')
  19. searchInput.clear()
  20. # searchInput.send_keys('6954767470573')
  21. # searchInput.send_keys('6923146102015')
  22. searchInput.send_keys(cell.value)
  23.  
  24. button = driver.find_element_by_id('gdsBtn')
  25. button.click()
  26.  
  27. tiaomaID4 = driver.find_element_by_class_name('p-info').find_elements_by_tag_name("a")[0].text
  28. changshang5 = driver.find_element_by_id('repList_ctl00_firmLink').text
  29. zhuangtai6 = driver.find_element_by_id('repList_ctl00_status').text[0:2]
  30. time.sleep(3)
  31. ret = driver.find_element_by_class_name('p-info').find_elements_by_tag_name("a")[0].get_attribute("href")
  32. driver.get(ret)
  33.  
  34. name7 = driver.find_element_by_id('Att_Sys_zh-cn_141_G').text
  35. ename8 = driver.find_element_by_id('Att_Sys_en-us_141_G').text
  36. fenlei9 = driver.find_element_by_id('Att_Sys_zh-cn_22_G').text
  37. pinpai10 = driver.find_element_by_id('Att_Sys_zh-cn_304_G').text
  38. guige11 = driver.find_element_by_id('Att_Sys_zh-cn_332_G').text
  39. kuandu12 = driver.find_element_by_id('Att_Sys_zh-cn_101_G').text
  40. gaodu13 = driver.find_element_by_id('Att_Sys_zh-cn_106_G').text
  41. shendu14 = driver.find_element_by_id('Att_Sys_zh-cn_118_G').text
  42. yuanchanguo15 = driver.find_element_by_id('Att_Sys_zh-cn_74_G').text
  43. chandi16 = driver.find_element_by_id('Att_Sys_zh-cn_405_G').text
  44. zhuangpeiguo17 = driver.find_element_by_id('Att_Sys_zh-cn_171_G').text
  45. jibendanwei18 = driver.find_element_by_id('Att_Sys_zh-cn_107_G').text
  46. lingshoudanwei19 = driver.find_element_by_id('Att_Sys_zh-cn_204_G').text
  47. guanjianzi20 = driver.find_element_by_id('Att_Sys_zh-cn_11_G').text
  48. lingshoujia21 = driver.find_element_by_id('Att_Sys_zh-cn_196_G').text
  49.  
  50. try:
  51. img = driver.find_element_by_id('imageListDiv')
  52. except Exception as e:
  53. img = ''
  54.  
  55. sheet[get_column_letter(4) + str(cell.row)] = tiaomaID4
  56. sheet[get_column_letter(5) + str(cell.row)] = changshang5
  57. sheet[get_column_letter(6) + str(cell.row)] = zhuangtai6
  58. sheet[get_column_letter(7) + str(cell.row)] = name7
  59. sheet[get_column_letter(8) + str(cell.row)] = ename8
  60. sheet[get_column_letter(9) + str(cell.row)] = fenlei9
  61. sheet[get_column_letter(10) + str(cell.row)] = pinpai10
  62. sheet[get_column_letter(11) + str(cell.row)] = guige11
  63. sheet[get_column_letter(12) + str(cell.row)] = kuandu12
  64. sheet[get_column_letter(13) + str(cell.row)] = gaodu13
  65. sheet[get_column_letter(14) + str(cell.row)] = shendu14
  66. sheet[get_column_letter(15) + str(cell.row)] = yuanchanguo15
  67. sheet[get_column_letter(16) + str(cell.row)] = chandi16
  68. sheet[get_column_letter(17) + str(cell.row)] = zhuangpeiguo17
  69. sheet[get_column_letter(18) + str(cell.row)] = jibendanwei18
  70. sheet[get_column_letter(19) + str(cell.row)] = lingshoudanwei19
  71. sheet[get_column_letter(20) + str(cell.row)] = guanjianzi20
  72. sheet[get_column_letter(21) + str(cell.row)] = lingshoujia21
  73.  
  74. if img:
  75. sheet[get_column_letter(21) + str(cell.row)] = ret
  76.  
  77. wb.save(r'C:\Users\admin\Desktop\T1.xlsx')
  78. # print('end')
  79.  
  80. time.sleep(3)
  81. driver.back()
  82.  
  83. except Exception as e:
  84. print('%s 错误'%cell.value)
  85. time.sleep(3)
  86. driver.back()
  87.  
  88. wb.close()

python selenium 模块的更多相关文章

  1. python selenium模块调用浏览器的时候出错

    python selenium模块使用出错,这个怎么改 因为不同版本更新不同步问题,浏览器都要另外下一个驱动.

  2. python selenium模块 css定位

    selenium是python的非标准库,使用时需要下载安装 安装命令  pip install selenium selenium是python的自动化测试模块,可以模拟浏览器的行为 所以在使用之前 ...

  3. python + selenium 模块封装及参数化

    模块封装 示例代码: baidu.py from time import sleep from selenium import webdriver driver = webdriver.Chrome( ...

  4. python selenium 模块的安装及使用

    安装 pip install selenium 或者到https://pypi.python.org/pypi/selenium 下载setup安装包,之后进入目录后运行python setup.py ...

  5. python - selenium模块简介

    为什么要使用Selenium? 很多浏览器渲染页面的方式都很难找出其规律, 但是利用Selenium来驱动加载网页就可以直接拿到javaScript渲染后的结果了, 不需要再担心其相关的加密系统 声明 ...

  6. Python—selenium模块(浏览器自动化工具)

    selenium可以用来完成浏览器自动化相关的操作,写一些代码制定一些基于浏览器自动化的相关操作(行为动作),当代码执行后,浏览器就会自动触发相关的事件 安装方法: pip install selen ...

  7. python selenium模块 xpath定位

    ''' 附w3xpath语法地址 https://www.w3school.com.cn/xpath/xpath_syntax.asp 总结: 返回匹配到所有符合条件的第一个节点,对象是 <cl ...

  8. Python爬虫——selenium模块

    selenium模块介绍 selenium最初是一个测试工具,而爬虫中使用它主要是为了解决requests无法直接执行JavaScript代码的问题 selenium本质是通过驱动浏览器,完全模拟浏览 ...

  9. python 全栈开发,Day136(爬虫系列之第3章-Selenium模块)

    一.Selenium 简介 selenium最初是一个自动化测试工具,而爬虫中使用它主要是为了解决requests无法直接执行JavaScript代码的问题 selenium本质是通过驱动浏览器,完全 ...

随机推荐

  1. Oracle 11g全表扫描以Direct Path Read方式执行

    在Oracle Database 11g中有一个新特性,全表扫描可以通过直接路径读的方式来执行(Direct Path Read),这是一个合理的变化,如果全表扫描的大量数据读取是偶发性的,则直接路径 ...

  2. handsontable合并表头

    想在页面中做类似excel的操作,发现handsontable符合要求. 然后发现这个文章 http://blog.csdn.net/wynan830/article/details/9054195 ...

  3. codeblocks-17.12mingw-nosetup(mingw编译,绿色免安装版)的下载、安装及设置一

    一.先进入网址:http://www.codeblocks.org/downloads/,选择Download the binary release. 二.转换网页后,选择codeblocks-17. ...

  4. bboss oreach循环嵌套遍历map

    foreach循环嵌套遍历mapforeach嵌套dsl脚本定义 <property name="dynamicInnerDsl"> <![CDATA[{ ## ...

  5. 项目笔记-vue

    记录新建vue项目之后的种种. 2019年3月12日,从git上下载了一个vue后台模板的项目,git地址:https://github.com/lin-xin/vue-manage-system ( ...

  6. XAMPP支持多PHP版本

    在使用xampp进行开发的时候,我们都知道它只能支持一个PHP版本不能像PHPstudy那样方便进行不同版本的切换操作.因此我们手动的对于xampp进行改造一下,使其支持其他PHP版本 1. 从官网上 ...

  7. telnet-server、telnet

    1.查询yum仓库中的安装包 [root@localhost /]# yum list |grep telnettelnet.x86_64                              1 ...

  8. jQuery 模拟操作

    1.常用模拟 有时,需要通过模拟用户操作,来达到单击的效果.例如在用户进入页面后,就触发 click 事件,而不需要用户去主动单击.在 jQuery 中,可以使用 trigger() 方法完成模拟操作 ...

  9. springboot实现简单的文件上传

    承接上一篇,这里记录一下简单的springboot文件上传的方式 首先,springboot简单文件上传不需要添加额外的jar包和配置 这里贴一下后端controller层的实现代码 补一份前台的HT ...

  10. table 里输入rules 验证

    HTML <el-form ref='from' :model="fromData"> <el-table ref="tableman" bo ...