博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
漫话爬取
阅读量:4496 次
发布时间:2019-06-08

本文共 1427 字,大约阅读时间需要 4 分钟。

#!/usr/bin/env python# _*_ coding: utf-8 _*_# __author__ ='kong' from selenium import webdriverimport osimport time class GetCartoon(object):    def __init__(self):        self.startUrl = "http://www.1kkk.com/ch1-406302/"        self.browser = self.getBrowser()        self.saveCartoon()     def getBrowser(self):        browser = webdriver.PhantomJS()        try:            browser.get(self.startUrl)            browser.implicitly_wait(5)            print "url get ok"        except:            print "url get failed"        return browser     def createDir(self,fileName):        if os.path.exists(fileName):            print "dir is exists"        else:            os.makedirs(fileName)            print "dir create ok"     def saveCartoon(self):        fileName = self.browser.title.split("_")[0]        self.createDir(fileName)        os.chdir(fileName)        # 总共26页        sumPage = int(self.browser.find_element_by_xpath("//font[@class='zf40']/span[2]").text)        i = 1        while i <= sumPage:            imgName = str(i)+'.png'            # html页面保存成图片            self.bowser.get_screenshot_as_file(imgName)            i += 1            # 点击下一页按扭            NextTag = self.browser.find_element_by_id("next")            NextTag.click()            # 3秒后执行保存图片操作            time.sleep(3)        self.browser.close() if __name__ == '__main__':    GC = GetCartoon()

 

转载于:https://www.cnblogs.com/HomeG/p/10527146.html

你可能感兴趣的文章
正则表达式
查看>>
Date类
查看>>
基本类型的数值转换
查看>>
集合、泛型、增强for
查看>>
Public Key Retrieval is not allowed错误
查看>>
Unable to load authentication plugin 'caching_sha2_password'.错误
查看>>
The server time zone value '乱码' 错误
查看>>
require.js的用法
查看>>
基础语言知识C++
查看>>
如何使电脑彻底崩溃!!!!(不要干坏事哦)
查看>>
简单练习题
查看>>
记账本,C,Github,service
查看>>
约数定理(two)
查看>>
Pyenv和pip的安装及配置
查看>>
字典dict
查看>>
squid-正向代理
查看>>
《A First Course in Probability》-chaper7-极限定理-强大数定理
查看>>
Python类型转换+序列操作+基本概念辨析速查手册
查看>>
Python编程之数据结构与算法练习_010
查看>>
vi 常用技巧
查看>>