File tree Expand file tree Collapse file tree 2 files changed +10
-6
lines changed
Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -263,10 +263,13 @@ add_length = (len(keyword) - 2) * sizes['width'] / 15
263263
264264### 找到位置:
265265```
266+ # 跨浏览器兼容
267+ scroll = browser.execute_script("return window.scrollY;")
268+ top = locations['y'] - scroll
266269# 构造指数的位置
267270rangle = (
268- int(locations['x'] + sizes['width'] / 4 + add_length), int(locations['y'] + sizes['height'] / 2 - 40 ),
269- int(locations['x'] + sizes['width'] * 2 / 3), int(locations['y'] + sizes['height'] - 40 ))
271+ int(locations['x'] + sizes['width'] / 4 + add_length), int(top + sizes['height'] / 2),
272+ int(locations['x'] + sizes['width'] * 2 / 3), int(top + sizes['height']))
270273```
271274
272275### 后面的完整代码是:
Original file line number Diff line number Diff line change @@ -192,16 +192,17 @@ def getindex(keyword, day):
192192 imgelement = browser .find_element_by_xpath ('//div[@id="viewbox"]' )
193193 # 找到图片坐标
194194 locations = imgelement .location
195- print (locations )
195+ # 跨浏览器兼容
196+ scroll = browser .execute_script ("return window.scrollY;" )
197+ top = locations ['y' ] - scroll
196198 # 找到图片大小
197199 sizes = imgelement .size
198- print (sizes )
199200 # 构造关键词长度
200201 add_length = (len (keyword ) - 2 ) * sizes ['width' ] / 15
201202 # 构造指数的位置
202203 rangle = (
203- int (locations ['x' ] + sizes ['width' ] / 4 + add_length ), int (locations [ 'y' ] + sizes ['height' ] / 2 - 40 ),
204- int (locations ['x' ] + sizes ['width' ] * 2 / 3 ), int (locations [ 'y' ] + sizes ['height' ] - 40 ))
204+ int (locations ['x' ] + sizes ['width' ] / 4 + add_length ), int (top + sizes ['height' ] / 2 ),
205+ int (locations ['x' ] + sizes ['width' ] * 2 / 3 ), int (top + sizes ['height' ]))
205206 # 截取当前浏览器
206207 path = "../baidu/" + str (num )
207208 browser .save_screenshot (str (path ) + ".png" )
You can’t perform that action at this time.
0 commit comments