Selenium + PhantomJS + python图片全屏截取+定位坐标+抠图+图片识别
2017-12-14 10:10
411 查看
Selenium + PhantomJS + python图片全屏截取+定位坐标+抠图+图片识别
1.原图片(全屏截图)
#设置浏览器参数,伪装成浏览器
dcap = dict(DesiredCapabilities.PHANTOMJS) #设置userAgent
dcap["phantomjs.page.settings.userAgent"] = ("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:25.0) Gecko/20100101 Firefox/25.0 ")
#打开浏览器
wb = webdriver.PhantomJS(desired_capabilities=dcap)
url = "http://m.maoyan.com/shows/149?_v_=yes"
wb.maximize_window()
wb.get(url)
imgelement = wb.find_element_by_xpath('//div[@class="showtime-list"]/table/tbody/tr[1]/td[3]/span/span')
#图片坐标
locations = imgelement.location
print(locations)
#图片大小
sizes = imgelement.size
print(sizes)
# 构造指数的位置
rangle = (int(locations['x']),int(locations['y']),int(locations['x'] + sizes['width']),int(locations['y'] + sizes['height']))
print rangle
# 截取当前浏览器
path1 = "/home/bingcheng/maoyan_shotImage/maoyan_PSeat_image/" + str(2)
path2 = "/home/bingcheng/maoyan_shotImage/maoyan_seat_image/" + str(2)
wb.save_screenshot(str(path1) + ".png")
# 打开截图切割
img = Image.open(str(path1) + ".png")
jpg = img.crop(rangle)
jpg.save(str(path2) + ".png")
print "图片截取成功!"
#图像识别
image = Image.open(str(path2) + ".png")
image.load()
code = pytesseract.image_to_string(image)
print "图片内容识别为:"
print code
#关闭浏览器
wb.close()
print "结束"
2.定位坐标截图后的图片
3.识别后
64
1.原图片(全屏截图)
#设置浏览器参数,伪装成浏览器
dcap = dict(DesiredCapabilities.PHANTOMJS) #设置userAgent
dcap["phantomjs.page.settings.userAgent"] = ("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:25.0) Gecko/20100101 Firefox/25.0 ")
#打开浏览器
wb = webdriver.PhantomJS(desired_capabilities=dcap)
url = "http://m.maoyan.com/shows/149?_v_=yes"
wb.maximize_window()
wb.get(url)
imgelement = wb.find_element_by_xpath('//div[@class="showtime-list"]/table/tbody/tr[1]/td[3]/span/span')
#图片坐标
locations = imgelement.location
print(locations)
#图片大小
sizes = imgelement.size
print(sizes)
# 构造指数的位置
rangle = (int(locations['x']),int(locations['y']),int(locations['x'] + sizes['width']),int(locations['y'] + sizes['height']))
print rangle
# 截取当前浏览器
path1 = "/home/bingcheng/maoyan_shotImage/maoyan_PSeat_image/" + str(2)
path2 = "/home/bingcheng/maoyan_shotImage/maoyan_seat_image/" + str(2)
wb.save_screenshot(str(path1) + ".png")
# 打开截图切割
img = Image.open(str(path1) + ".png")
jpg = img.crop(rangle)
jpg.save(str(path2) + ".png")
print "图片截取成功!"
#图像识别
image = Image.open(str(path2) + ".png")
image.load()
code = pytesseract.image_to_string(image)
print "图片内容识别为:"
print code
#关闭浏览器
wb.close()
print "结束"
2.定位坐标截图后的图片
3.识别后
64
相关文章推荐
- python selenium截取指定元素图片
- selenium截取具体元素图片(python版)
- 基于Python的Selenium自动化(3)— 实现验证码截取并识别
- python爬虫三:获取一个网易用户的所有图片(selenium+phantomjs)
- selenium+python实现1688网站验证码图片的截取功能
- Python+selenium实现截图图片并保存截取的图片
- selenium,phantomJS,python整合的一个小示例,把某个网页画面整体保存成图片格式。
- [Python爬虫] 之二十六:Selenium +phantomjs 利用 pyquery抓取智能电视网站图片信息
- Python图片识别找坐标(appium通过识别图片点击坐标)
- Python_selenium之获取当前页面的href属性,id属性,图片信息和截全屏
- java+selenium 截取某一元素的图片的方法
- python识别图片内容
- 基于Python,Selenium和PhantomJS实现动态页面爬取
- python+selenium 识别简单的二维码
- python图片(验证码)识别环境搭建(基于centos7)
- Selenium2+python自动化7-xpath定位
- 基于Python3的phantomJs+Selenium动态网页爬取技术
- [Python爬虫] 之二十:Selenium +phantomjs 利用 pyquery通过搜狗搜索引擎数据
- Python_python图片识别小程序
- 轻松自动化---selenium-webdriver(python) (五)---层级定位