51job_selenium测试2
Python爬虫视频教程零基础小白到scrapy爬虫高手-轻松入门
https://item.taobao.com/item.htm?spm=a1z38n.10677092.0.0.482434a6EmUbbW&id=564564604865
# -*- coding: utf-8 -*-
"""
Spyder Editor This is a temporary script file.
""" import requests,bs4,openpyxl,time,selenium
from openpyxl.cell import get_column_letter,column_index_from_string
from selenium import webdriver
excelName="51job.xlsx"
sheetName="Sheet1"
wb1=openpyxl.load_workbook(excelName)
sheet=wb1.get_sheet_by_name(sheetName)
start=1 charset="gb2312"
site="http://jobs.51job.com/all/co198308.html"
browser=webdriver.Firefox()
browser.get(site)
linkElem=browser.find_element_by_link_text("下一页")
linkElem.click()
#elem = browser.find_element_by_class_name('el')
#返回标签的值
#elem.text
#elems = browser.find_elements_by_class_name('el')
elem=browser.find_elements_by_class_name('el')
div1=elem[0].text
div2=elem[1].text #每个网站爬取相应数据
def Craw(site): res=requests.get(site)
res.encoding = charset
soup1=bs4.BeautifulSoup(res.text,"lxml")
div=soup1.select('.el')
len_div=len(div)
for i in range(len_div):
#print ("i:",i)
content=div[i].getText()
content_list=content.split('\n') name=content_list[1]
#print ("name:",name)
education=content_list[2]
#print ("education:",education)
position=content_list[3]
#print ("position:",position)
salary=content_list[4]
#print ("salary:",salary)
date=content_list[5]
#print ("date:",date) sheet['A'+str(i+2)].value=name
sheet['B'+str(i+2)].value=education
sheet['C'+str(i+2)].value=position
sheet['D'+str(i+2)].value=salary
sheet['E'+str(i+2)].value=date '''
Craw(site)
wb1.save(excelName)
'''

Finding Elements on the Page
WebDriver objects have quite a few methods for finding elements on a page. They are divided into the find_element_* and find_elements_* methods. Thefind_element_* methods return a single WebElement object, representing the first element on the page that matches your query. The find_elements_* methods return a list of WebElement_* objects for every matching element on the page.
Table 11-3 shows several examples of find_element_* and find_elements_* methods being called on a WebDriver object that’s stored in the variable browser.
Table 11-3. Selenium’s WebDriver Methods for Finding Elements
|
Method name |
WebElement object/list returned |
|---|---|
browser.find_element_by_class_name(name) |
Elements that use the CSS class |
browser.find_element_by_css_selector(selector) |
Elements that match the CSS |
browser.find_element_by_id(id) |
Elements with a matching |
browser.find_element_by_link_text(text) |
|
browser.find_element_by_partial_link_text(text) |
|
browser.find_element_by_name(name) |
Elements with a matching |
browser.find_element_by_tag_name(name) |
Elements with a matching tag |
Except for the *_by_tag_name() methods, the arguments to all the methods are case sensitive. If no elements exist on the page that match what the method is looking for, the selenium module raises a NoSuchElement exception. If you do not want this exception to crash your program, add try and except statements to your code.
Once you have the WebElement object, you can find out more about it by reading the attributes or calling the methods in Table 11-4.
Table 11-4. WebElement Attributes and Methods
|
Attribute or method |
Description |
|---|---|
|
|
The tag name, such as |
|
|
The value for the element’s |
|
|
The text within the element, such as |
|
|
For text field or text area elements, clears the text typed into it |
|
|
Returns |
|
|
For input elements, returns |
|
|
For checkbox or radio button elements, returns |
|
|
A dictionary with keys |
Table 11-5. Commonly Used Variables in the selenium.webdriver.common.keysModule
|
Attributes |
Meanings |
|---|---|
|
|
The keyboard arrow keys |
|
|
The ENTER and RETURN keys |
|
|
The |
|
|
The ESC, BACKSPACE, and DELETE keys |
|
|
The F1 to F12 keys at the top of the keyboard |
|
|
The TAB key |
51job_selenium测试2的更多相关文章
- 51job_selenium测试
Python爬虫视频教程零基础小白到scrapy爬虫高手-轻松入门 https://item.taobao.com/item.htm?spm=a1z38n.10677092.0.0.482434a6E ...
- SignalR系列续集[系列8:SignalR的性能监测与服务器的负载测试]
目录 SignalR系列目录 前言 也是好久没写博客了,近期确实很忙,嗯..几个项目..头要炸..今天忙里偷闲.继续我们的小系列.. 先谢谢大家的支持.. 我们来聊聊SignalR的性能监测与服务器的 ...
- Apache Ignite之集群应用测试
集群发现机制 在Ignite中的集群号称是无中心的,而且支持命令行启动和嵌入应用启动,所以按理说很简单.而且集群有自动发现机制感觉对于懒人开发来说太好了,抱着试一试的心态测试一下吧. 在Apache ...
- 测试一下StringBuffer和StringBuilder及字面常量拼接三种字符串的效率
之前一篇里写过字符串常用类的三种方式<java中的字符串相关知识整理>,只不过这个只是分析并不知道他们之间会有多大的区别,或者所谓的StringBuffer能提升多少拼接效率呢?为此写个简 ...
- TechEmpower 13轮测试中的ASP.NET Core性能测试
应用性能直接影响到托管服务的成本,因此公司在开发应用时需要格外注意应用所使用的Web框架,初创公司尤其如此.此外,糟糕的应用性能也会影响到用户体验,甚至会因此受到相关搜索引擎的降级处罚.在选择框架时, ...
- .NET Core系列 :4 测试
2016.6.27 微软已经正式发布了.NET Core 1.0 RTM,但是工具链还是预览版,同样的大量的开源测试库也都是至少发布了Alpha测试版支持.NET Core, 这篇文章 The Sta ...
- 渗透测试工具BurpSuite做网站的安全测试(基础版)
渗透测试工具BurpSuite做网站的安全测试(基础版) 版权声明:本文为博主原创文章,未经博主允许不得转载. 学习网址: https://t0data.gitbooks.io/burpsuite/c ...
- 在ubuntu16.10 PHP测试连接MySQL中出现Call to undefined function: mysql_connect()
1.问题: 测试php7.0 链接mysql数据库的时候发生错误: Fatal error: Uncaught Error: Call to undefined function mysqli_con ...
- 【初学python】使用python调用monkey测试
目前公司主要开发安卓平台的APP,平时测试经常需要使用monkey测试,所以尝试了下用python调用monkey,代码如下: import os apk = {'j': 'com.***.test1 ...
随机推荐
- 软件工程个人项目作业 Individual Project
利用Junit4进行程序模块的测试,回归测试 源码 https://github.com/dpch16303/test/blob/master/%E5%9B%9E%E5%BD%92%E6%B5%8B% ...
- [CB]2018全球半导体营收4700亿美元 三星继续碾压英特尔
2018全球半导体营收4700亿美元 三星继续碾压英特尔 https://www.cnbeta.com/articles/tech/808833.htm Gartner最新报告显示,2018年全球半导 ...
- sql 表,字段(列),表数据(行)相关命令
随便转载,保留出处:http://www.cnblogs.com/aaron-agu/ 注: 以下所有操作都在登陆数据库后执行 命令use test; test为数据库名 查看表 show tabl ...
- Delphi中的Sender:TObject对象解析
Delphi中的Sender:TObject对象解析 procedure TForm1.Button1Click(Sender: TObject); begin end; 解析:Procedure是过 ...
- jvm学习二:类加载器
前一节详细的聊了一下类的加载过程,本节聊一聊类的加载工具,类加载器 --- ClassLoader 本想自己写的,查资料的时候查到一篇大神的文章,写的十分详细 大家直接过去看吧http://blo ...
- 【Java】 内部类
[Java]内部类 可以将一个类的定义放在另一个类的定义内部,这就是内部类. 使用内部类的的原因主要有三点: 内部类方法可以访问该类定义所在的作用域中的数据,包括私有的数据. 内部类可以对同一个包中的 ...
- BZOJ4229选择——LCT+并查集+离线(LCT动态维护边双连通分量)
题目描述 现在,我想知道自己是否还有选择. 给定n个点m条边的无向图以及顺序发生的q个事件. 每个事件都属于下面两种之一: 1.删除某一条图上仍存在的边 2.询问是否存在两条边不相交的路径可以从点u出 ...
- BZOJ2006[NOI2010]超级钢琴——堆+主席树
题目描述 小Z是一个小有名气的钢琴家,最近C博士送给了小Z一架超级钢琴,小Z希望能够用这架钢琴创作出世界上最美妙的 音乐. 这架超级钢琴可以弹奏出n个音符,编号为1至n.第i个音符的美妙度为Ai,其中 ...
- Assign the task HDU - 3974(dfs序+线段树)
There is a company that has N employees(numbered from 1 to N),every employee in the company has a im ...
- poj3278 【BFS】
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 97240 Accepted: 30519 ...