zoukankan      html  css  js  c++  java
  • PhantomJS介绍与使用

    一、什么是PhantomJS?

      一款无界面浏览器。

    二、python如何爬取动态加载页面?

      selenium+PhantomJS(爬虫终极解决方案)

    三、selenium操作PhantomJS

    1、下载PhantomJS

    https://phantomjs.org/download.html

    2、代码示例

    #!/usr/local/bin/python3.7
    
    from selenium import webdriver
    import time
    
    # phantomJS路径
    path = '/Users/mozili/Documents/PhantomJS/phantomjs-2.1.1-macosx/bin/phantomjs'
    # 创建浏览器对象
    browser = webdriver.PhantomJS(path)
    
    # 打开百度并操作
    url = 'https://www.baidu.com'
    browser.get(url)
    time.sleep(1)
    # 截图
    browser.save_screenshot('Reptile/phantomjs_img/baidu.png')
    # 定位搜索框
    search = browser.find_element_by_id('kw')
    time.sleep(1)
    # 在搜索框输入内容
    search.send_keys('美女')
    time.sleep(1)
    # 截图
    browser.save_screenshot('Reptile/phantomjs_img/meinv.png')
    # 关闭浏览器
    browser.quit()
  • 相关阅读:
    CodeForces
    网络流
    poj 2185
    树的分治学习
    数位DP
    URAL 1969. Hong Kong Tram
    hdu 4759 Poker Shuffle
    hdu3712 Detector Placement
    分块思想
    莫比乌斯反演
  • 原文地址:https://www.cnblogs.com/lxmtx/p/13019902.html
Copyright © 2011-2022 走看看