获取验证码图片 :return: 图片的location信息
(self, bg_filename = 'bg.jpg', fullbg_filename = 'fullbg.jpg')
| 92 | bowton.click() |
| 93 | |
| 94 | def get_images(self, bg_filename = 'bg.jpg', fullbg_filename = 'fullbg.jpg'): |
| 95 | """ |
| 96 | 获取验证码图片 |
| 97 | :return: 图片的location信息 |
| 98 | """ |
| 99 | bg = [] |
| 100 | fullgb = [] |
| 101 | while bg == [] and fullgb == []: |
| 102 | bf = BeautifulSoup(self.browser.page_source, 'lxml') |
| 103 | bg = bf.find_all('div', class_ = 'gt_cut_bg_slice') |
| 104 | fullgb = bf.find_all('div', class_ = 'gt_cut_fullbg_slice') |
| 105 | bg_url = re.findall('url\(\"(.*)\"\);', bg[0].get('style'))[0].replace('webp', 'jpg') |
| 106 | fullgb_url = re.findall('url\(\"(.*)\"\);', fullgb[0].get('style'))[0].replace('webp', 'jpg') |
| 107 | bg_location_list = [] |
| 108 | fullbg_location_list = [] |
| 109 | for each_bg in bg: |
| 110 | location = {} |
| 111 | location['x'] = int(re.findall('background-position: (.*)px (.*)px;',each_bg.get('style'))[0][0]) |
| 112 | location['y'] = int(re.findall('background-position: (.*)px (.*)px;',each_bg.get('style'))[0][1]) |
| 113 | bg_location_list.append(location) |
| 114 | for each_fullgb in fullgb: |
| 115 | location = {} |
| 116 | location['x'] = int(re.findall('background-position: (.*)px (.*)px;',each_fullgb.get('style'))[0][0]) |
| 117 | location['y'] = int(re.findall('background-position: (.*)px (.*)px;',each_fullgb.get('style'))[0][1]) |
| 118 | fullbg_location_list.append(location) |
| 119 | |
| 120 | urlretrieve(url = bg_url, filename = bg_filename) |
| 121 | print('缺口图片下载完成') |
| 122 | urlretrieve(url = fullgb_url, filename = fullbg_filename) |
| 123 | print('背景图片下载完成') |
| 124 | return bg_location_list, fullbg_location_list |
| 125 | |
| 126 | def get_merge_image(self, filename, location_list): |
| 127 | """ |