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)
browser.find_elements_by_class_name(name)

Elements that use the CSS class name

browser.find_element_by_css_selector(selector)
browser.find_elements_by_css_selector(selector)

Elements that match the CSS selector

browser.find_element_by_id(id)
browser.find_elements_by_id(id)

Elements with a matching id attribute value

browser.find_element_by_link_text(text)
browser.find_elements_by_link_text(text)

<a> elements that completely match the textprovided

browser.find_element_by_partial_link_text(text)
browser.find_elements_by_partial_link_text(text)

<a> elements that contain the text provided

browser.find_element_by_name(name)
browser.find_elements_by_name(name)

Elements with a matching name attribute value

browser.find_element_by_tag_name(name)
browser.find_elements_by_tag_name(name)

Elements with a matching tag name (case insensitive; an <a> element is matched by 'a'and 'A')

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

tag_name

The tag name, such as 'a' for an <a> element

get_attribute(name)

The value for the element’s name attribute

text

The text within the element, such as 'hello' in <span>hello</span>

clear()

For text field or text area elements, clears the text typed into it

is_displayed()

Returns True if the element is visible; otherwise returns False

is_enabled()

For input elements, returns True if the element is enabled; otherwise returns False

is_selected()

For checkbox or radio button elements, returns True if the element is selected; otherwise returns False

location

A dictionary with keys 'x' and 'y' for the position of the element in the page

Table 11-5. Commonly Used Variables in the selenium.webdriver.common.keysModule

Attributes

Meanings

Keys.DOWNKeys.UPKeys.LEFTKeys.RIGHT

The keyboard arrow keys

Keys.ENTERKeys.RETURN

The ENTER and RETURN keys

Keys.HOMEKeys.ENDKeys.PAGE_DOWN,Keys.PAGE_UP

The homeendpagedown, and pageup keys

Keys.ESCAPEKeys.BACK_SPACEKeys.DELETE

The ESC, BACKSPACE, and DELETE keys

Keys.F1Keys.F2,..., Keys.F12

The F1 to F12 keys at the top of the keyboard

Keys.TAB

The TAB key

51job_selenium测试2的更多相关文章

  1. 51job_selenium测试

    Python爬虫视频教程零基础小白到scrapy爬虫高手-轻松入门 https://item.taobao.com/item.htm?spm=a1z38n.10677092.0.0.482434a6E ...

  2. SignalR系列续集[系列8:SignalR的性能监测与服务器的负载测试]

    目录 SignalR系列目录 前言 也是好久没写博客了,近期确实很忙,嗯..几个项目..头要炸..今天忙里偷闲.继续我们的小系列.. 先谢谢大家的支持.. 我们来聊聊SignalR的性能监测与服务器的 ...

  3. Apache Ignite之集群应用测试

    集群发现机制 在Ignite中的集群号称是无中心的,而且支持命令行启动和嵌入应用启动,所以按理说很简单.而且集群有自动发现机制感觉对于懒人开发来说太好了,抱着试一试的心态测试一下吧. 在Apache ...

  4. 测试一下StringBuffer和StringBuilder及字面常量拼接三种字符串的效率

    之前一篇里写过字符串常用类的三种方式<java中的字符串相关知识整理>,只不过这个只是分析并不知道他们之间会有多大的区别,或者所谓的StringBuffer能提升多少拼接效率呢?为此写个简 ...

  5. TechEmpower 13轮测试中的ASP.NET Core性能测试

    应用性能直接影响到托管服务的成本,因此公司在开发应用时需要格外注意应用所使用的Web框架,初创公司尤其如此.此外,糟糕的应用性能也会影响到用户体验,甚至会因此受到相关搜索引擎的降级处罚.在选择框架时, ...

  6. .NET Core系列 :4 测试

    2016.6.27 微软已经正式发布了.NET Core 1.0 RTM,但是工具链还是预览版,同样的大量的开源测试库也都是至少发布了Alpha测试版支持.NET Core, 这篇文章 The Sta ...

  7. 渗透测试工具BurpSuite做网站的安全测试(基础版)

    渗透测试工具BurpSuite做网站的安全测试(基础版) 版权声明:本文为博主原创文章,未经博主允许不得转载. 学习网址: https://t0data.gitbooks.io/burpsuite/c ...

  8. 在ubuntu16.10 PHP测试连接MySQL中出现Call to undefined function: mysql_connect()

    1.问题: 测试php7.0 链接mysql数据库的时候发生错误: Fatal error: Uncaught Error: Call to undefined function mysqli_con ...

  9. 【初学python】使用python调用monkey测试

    目前公司主要开发安卓平台的APP,平时测试经常需要使用monkey测试,所以尝试了下用python调用monkey,代码如下: import os apk = {'j': 'com.***.test1 ...

随机推荐

  1. "Linux内核分析"第七周

    可执行程序的装载 张文俊+原创作品转载请注明出处+<Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 一.预 ...

  2. This Android SDK requires Android Developer Toolkit version 17.0.0 or above. Current version is 10.0.0.v201102162101-104271. Please update ADT to the latest version.

    win7/xp 下面安装Android虚拟机,更新SDK后,在Eclipse preference里指向android-sdk-windows时. 出现 : This Android SDK requ ...

  3. QT下opencv的编译和使用

    需要的文件 qt-opensource-windows-x86-mingw491_opengl-5.4.0.exe cmake-3.12.0-rc1-win64-x64.msi opencv-2.4. ...

  4. 收获,不止oracle

    物理体系 体系结构图 缩放 1.Oracle由实例和数据库组成,上半部分的直角方框为实例instance,下半部分的圆角方框为数据库Database. 2.实例是由一个开辟的共享内存区SGA(Syst ...

  5. Maven的课堂笔记1

    1 什么是maven? Maven是一个跨平台的项目管理工具,主要用于基于java平台的项目构建,依赖管理. Clean  compile  test  package  install   run ...

  6. shell脚本--权限分配

    因为shell脚本内部是很多命令的集合,这些命令也许会涉及到操作某一个文件,而且shell脚本的运行,也是需要当前用户对脚本具有运行的权限,否则,会因为权限不够而失败. 首先最重要的一点:修改权限,只 ...

  7. JQuery 操作 radio 被坑一例

    .removeAttr('checked'); .prop('checked',false); .prop('checked',true); 与 .attr("checked",t ...

  8. [转帖]Intel新一代Xeon完整曝光

    AMD已经官宣7nm工艺的第二代EPYC霄龙服务器平台,今年上半年就会大规模出货,而在Intel这边,由于10nm工艺进展还是不够快,在服务器上还是需要14nm继续打天下,而且还有两代14nm工艺产品 ...

  9. pandas重新索引

    #重新索引会更改DataFrame的行标签和列标签.重新索引意味着符合数据以匹配特定轴上的一组给定的标签. #可以通过索引来实现多个操作 - #重新排序现有数据以匹配一组新的标签. #在没有标签数据的 ...

  10. grep 匹配打印的上下几行

    如果在只是想匹配模式的上下几行,grep可以实现.   $grep -5 'parttern' inputfile //打印匹配行的前后5行   $grep -C 5 'parttern' input ...