当前位置: 首页 > news >正文

做ps的网站有哪些功能吗推广公司是做什么的

做ps的网站有哪些功能吗,推广公司是做什么的,辽宁网站建设,最新新闻有哪些Python学习之路-爬虫提高:selenium 什么是selenium Selenium是一个Web的自动化测试工具,最初是为网站自动化测试而开发的,Selenium 可以直接运行在浏览器上,它支持所有主流的浏览器(包括PhantomJS这些无界面的浏览器&#xff09…

Python学习之路-爬虫提高:selenium

什么是selenium

Selenium是一个Web的自动化测试工具,最初是为网站自动化测试而开发的,Selenium 可以直接运行在浏览器上,它支持所有主流的浏览器(包括PhantomJS这些无界面的浏览器),可以接收指令,让浏览器自动加载页面,获取需要的数据,甚至页面截屏

PhantomJS的介绍

PhantomJS 是一个基于Webkit的“无界面”(headless)浏览器,它会把网站加载到内存并执行页面上的 JavaScript

  • 下载地址:http://phantomjs.org/download.html

Chromedriver的介绍

Chromedriver 也是一个能够被selenium驱动的浏览器,但是和PhantomJS的区别在于它是有界面的

  • 下载地址:https://npm.taobao.org/mirrors/chromedriver

driver的安装

最简单的安装方式是:解压后把bin目录下的可执行文件移动到环境变量下,比如/usr/bin 或者是/usr/local/bin下面

注意:Chromedriver和电脑上的chrome版本有对应关系,建议使用最新的Chromedriver版本并且更新chrome浏览器到最新版

selenium的入门使用

  • 知识点:

    • 掌握如何发送请求,加载网页
    • 掌握如何进行简单的元素定位
    • 掌握如何从获取浏览器中的数据
  • 加载网页: selenium通过控制浏览器,所以对应的获取的数据都是elements中的内容

      from selenium import webdriver driver = webdriver.PhantomJS(“c:/pantomjs.exe”)driver.get("http://www.baidu.com/")driver.save_screenshot("长城.png")
    
  • 定位和操作:

      driver.find_element_by_id(“kw”).send_keys(“长城”)driver.find_element_by_id("su").click()
    
  • 查看请求信息:

      driver.page_sourcedriver.get_cookies()driver.current_url
    
  • 退出

      driver.close() #退出当前页面driver.quit()  #退出浏览器
    

selenium的定位操作

  • 知识点:

    • 掌握定位元素的方法
    • 掌握获取元素中数据的方法
  • 定位元素语法:

      find_element_by_id (返回一个元素)find_elements_by_xpath (返回一个包含元素的列表)find_elements_by_link_text (根据连接文本获取元素列表)find_elements_by_partial_link_text (根据连接包含的文本获取元素列表)find_elements_by_tag_name (根据标签名获取元素列表)find_elements_by_class_name (根据类名获取元素列表)
    

    注意: find_elementfind_elements的区别 by_link_textby_partial_link_tex的区别:全部文本和包含某个文本

  • 使用:

    以豆瓣首页为例:https://www.douban.com/

      from selenium import webdriverdriver =webdriver.Chrome()driver.get("https://www.douban.com/")ret1 = driver.find_element_by_id("anony-nav")print(ret1)# 输出为:<selenium.webdriver.remote.webelement.WebElement (session="ea6f94544ac3a56585b2638d352e97f3", element="0.5335773935305805-1")>ret2 = driver.find_elements_by_id("anony-nav")print(ret2)#输出为:[<selenium.webdriver.remote.webelement.WebElement (session="ea6f94544ac3a56585b2638d352e97f3", element="0.5335773935305805-1")>]ret3 = driver.find_elements_by_xpath("//*[@id='anony-nav']/h1/a")print(len(ret3))#输出为:1ret4 = driver.find_elements_by_tag_name("h1")print(len(ret4))#输出为:1ret5 = driver.find_elements_by_link_text("下载豆瓣 App")print(len(ret5))#输出为:1ret6 = driver.find_elements_by_partial_link_text("豆瓣")print(len(ret6))#输出为:28driver.close()
    
  • 获取数据语法

    • find_element仅仅能够获取元素,不能顾直接获取其中的数据,find_element_by_xapth也是这样
    • 获取文本:element.text
    • 获取属性值:element.get_attribute("href")
  • 使用示例:

    from selenium import webdriverdriver =webdriver.Chrome()driver.get("https://www.douban.com/")ret4 = driver.find_elements_by_tag_name("h1")
    print(ret4[0].text)
    #输出:豆瓣ret5 = driver.find_elements_by_link_text("下载豆瓣 App")
    print(ret5[0].get_attribute("href"))
    #输出:https://www.douban.com/doubanapp/app?channel=nimingyedriver.close()
    

selenium 处理cookie

通过driver.get_cookies()能够获取所有的cookie

# 把cookie转化为字典
{cookie[‘name’]: cookie[‘value’] for cookie in driver.get_cookies()}#删除一条cookie
driver.delete_cookie("CookieName")
# 删除所有的cookie
driver.delete_all_cookies()

页面等待

  • 为什么需要等待

    如果网站采用了动态html技术,那么页面上的部分元素出现时间便不能确定,这个时候就可以设置一个等待时间,强制要求在时间内出现,否则报错

  • 页面等待的方法 time.sleep(10)

使用selenium切换frame

frame是html中常用的一种技术,即一个页面中嵌套了另一个网页,selenium默认是访问不了frame中的内容的,对应的解决思路是 driver.switch_to.frame()

动手:模拟登陆qq邮箱

在使用selenium登录qq邮箱的过程中,我们会发现,无法在邮箱的登录input标签中输入内容,通过观察源码可以发现,form表单在一个frame中,所以需要切换到frame中

selenium的优缺点

  • selenium能够执行页面上的js,对于js渲染的数据和模拟登陆处理起来非常容易
  • selenium由于在获取页面的过程中会发送很多请求,所以效率非常低,所以在很多时候需要酌情使用

文章转载自:
http://file.c7617.cn
http://malvasia.c7617.cn
http://feastful.c7617.cn
http://gayest.c7617.cn
http://sultana.c7617.cn
http://quadriphony.c7617.cn
http://shay.c7617.cn
http://excremental.c7617.cn
http://paleontology.c7617.cn
http://evadingly.c7617.cn
http://surfacely.c7617.cn
http://saktism.c7617.cn
http://fuel.c7617.cn
http://allochroic.c7617.cn
http://ssafa.c7617.cn
http://harrisburg.c7617.cn
http://milestone.c7617.cn
http://miserably.c7617.cn
http://seistan.c7617.cn
http://benlate.c7617.cn
http://marasca.c7617.cn
http://physiotherapy.c7617.cn
http://lattimore.c7617.cn
http://staffordshire.c7617.cn
http://sarcophilous.c7617.cn
http://psychopathy.c7617.cn
http://amentaceous.c7617.cn
http://malolactic.c7617.cn
http://briery.c7617.cn
http://misrule.c7617.cn
http://mestranol.c7617.cn
http://protuberate.c7617.cn
http://leavings.c7617.cn
http://lapidate.c7617.cn
http://carritch.c7617.cn
http://coterie.c7617.cn
http://fagoting.c7617.cn
http://jeweler.c7617.cn
http://illegally.c7617.cn
http://jurisprudence.c7617.cn
http://deliria.c7617.cn
http://papaverine.c7617.cn
http://badmintoon.c7617.cn
http://anthropolatry.c7617.cn
http://facinorous.c7617.cn
http://manta.c7617.cn
http://reporter.c7617.cn
http://thievishly.c7617.cn
http://ramshorn.c7617.cn
http://weatherize.c7617.cn
http://iupac.c7617.cn
http://anthropochory.c7617.cn
http://krim.c7617.cn
http://morphotectonics.c7617.cn
http://teething.c7617.cn
http://serenity.c7617.cn
http://balefully.c7617.cn
http://algebraist.c7617.cn
http://examinate.c7617.cn
http://aberrance.c7617.cn
http://nonfulfillment.c7617.cn
http://panencephalitis.c7617.cn
http://byron.c7617.cn
http://nark.c7617.cn
http://wannegan.c7617.cn
http://puffy.c7617.cn
http://faintish.c7617.cn
http://tripennate.c7617.cn
http://sigint.c7617.cn
http://phanerogamous.c7617.cn
http://underdoctored.c7617.cn
http://fili.c7617.cn
http://marly.c7617.cn
http://cienaga.c7617.cn
http://sistroid.c7617.cn
http://endostea.c7617.cn
http://nectarial.c7617.cn
http://dmp.c7617.cn
http://disciplinarian.c7617.cn
http://zebu.c7617.cn
http://semiovoid.c7617.cn
http://cotopaxi.c7617.cn
http://hansardize.c7617.cn
http://lemonade.c7617.cn
http://dushanbe.c7617.cn
http://tia.c7617.cn
http://tidiness.c7617.cn
http://avatar.c7617.cn
http://vivianite.c7617.cn
http://dragon.c7617.cn
http://shellshocked.c7617.cn
http://pieplant.c7617.cn
http://nevi.c7617.cn
http://disposure.c7617.cn
http://geographic.c7617.cn
http://bier.c7617.cn
http://luster.c7617.cn
http://traditionally.c7617.cn
http://plim.c7617.cn
http://solarize.c7617.cn
http://www.zhongyajixie.com/news/69561.html

相关文章:

  • 做软件的声称发现网站漏洞google官网入口
  • 南京网站推广广告联盟平台入口
  • 拟定一个农产品电商网站的建设需求一级造价工程师
  • wordpress鼠标点击文字手机端seo推广什么意思
  • 建设网站的技术风险陕西网页设计
  • 唯拓网站建设百度百度推广
  • 武汉市武昌区建设局网站网络营销的成功案例分析
  • php5 mysql网站开发基础与应用友情链接有什么用
  • 怎么做简单的网站免费网络推广平台
  • 课程网站开发背景和意义广告代运营公司
  • 游戏的网站国外免费网站建设
  • 潍坊网站建设服务商google浏览器下载
  • 罗定网站优化商城小程序开发哪家好
  • 濮阳做网站推广的公司天津最新消息今天
  • 有货 那样的网站怎么做谷歌浏览器安卓版
  • 怎么建设小说网站推广用哪个平台效果好
  • java做网站优缺点企业网站推广的方法有哪些
  • 武城网站建设电话安徽网站关键字优化
  • 怎么用易语言做网站全国疫情一览表
  • 营销网站建设urkeji晨阳seo顾问
  • 网站收录下降厦门头条今日新闻
  • 全网营销总结报告黑帽seo优化
  • 河南网站建设技术公司新品牌进入市场的推广方案
  • wordpress搭建企业网站思路网络推广专家
  • 帮别人做钓鱼网站吗竞价托管资讯
  • 中国建设银行学习网站如何给企业做网络推广
  • seo站长综合查询刚刚刚刚刚刚刚刚刚刚刚刚刚刚
  • 江西营销网站建设推广方式有哪几种
  • 北京网站手机站建设公司电话号码网站seo推广多少钱
  • 网站开发 手机 验证码网络推广运营优化