您的位置:首页 > 编程语言 > Python开发

python爬虫 -- 截图网页中的图片(先Mark下,待改善)

2018-01-19 16:35 393 查看
# -*- coding: utf-8 -*-

from selenium import webdriver
from PIL import Image

if __name__ == '__main__':
codePrefix = u'https://kyfw.12306.cn/passport/captcha/captcha-image'
wbe = webdriver.PhantomJS('/usr/bin/phantomjs')
wbe.get("https://kyfw.12306.cn/otn/login/init")
# 此处有问题,还待解决,学习爬虫中,,,,,,
#element = wbe.find_element_by_xpath('//*[@id="loginForm"]/div/ul[1]/li[4]/div/div/div[2]/img')
element = wbe.find_element_by_xpath('//*[contains(@class_name="touclick-image")]')
left = element.location['x']
top = element.location['y']
right = element.location['x'] + element.size['width']
bottom = element.location['y'] + element.size['height']
im = Image.open(r'登录页.png')# 全页面截屏
im = im.crop((left, top, right, bottom))
im.save('验证码.png')

r'''
Message: 'phantomjs' executable needs to be in PATH.
geckodriver 要自行下载
phantomjs 自行下载
'''

def get_image():
pass
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: