forked from smilejay/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselenium_capture_firefox.py
More file actions
42 lines (33 loc) · 977 Bytes
/
selenium_capture_firefox.py
File metadata and controls
42 lines (33 loc) · 977 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding: utf-8 -*-
from selenium import webdriver
import time
def capture(url, img_file="test1.png"):
firefox = webdriver.Firefox()
firefox.set_window_size(1200, 900)
firefox.get(url)
firefox.execute_script("""
(function () {
var y = 0;
var step = 100;
window.scroll(0, 0);
function f() {
if (y < document.body.scrollHeight) {
y += step;
window.scroll(0, y);
setTimeout(f, 50);
} else {
window.scroll(0, 0);
document.title += "scroll-done";
}
}
setTimeout(f, 1000);
})();
""")
for i in xrange(30):
if "scroll-done" in firefox.title:
break
time.sleep(1)
firefox.save_screenshot(img_file)
firefox.close()
if __name__ == "__main__":
capture("http://www.taobao.com")