#!/usr/bin/env python
from selenium import webdriver
import time
import MySQLdb
import urllib
drivers = ['PhantomJS']
dervers_time = {
'PhantomJS' : 0,
}
times = 5
# def run_with_Chrome():
# common_step(webdriver.Chrome(executable_path='/Users/zhaowei/Downloads/chromedriver'))
def run_with_PhantomJS(webrow):
common_step(webrow,webdriver.PhantomJS(executable_path=r'/Users/zhaowei/Downloads/package/phantomjs-2.1.1-macosx/bin/phantomjs'))
def common_step(webrow,driver):
driver.get("http://%s"%webrow)
driver.save_screenshot('picture/%s.png'%webrow)
# status=urllib.urlopen("http://%s"%webrow).code
# print status
# ele = driver.find_element_by_id('su')
# print ele.get_attribute('value')
driver.quit()
try:
conn=MySQLdb.connect(
host='127.0.0.1',
port = 3306,
user='root',
passwd='',
db ='security',
)
cur = conn.cursor()
cur.execute("SELECT IP from webdata limit 0,2")
data = cur.fetchall()
print "Database: "
conn.close()
except:
print "Database number error"
for row in data:
start = time.time()
print start
print row[0]
run_with_PhantomJS(row[0])
end = time.time()
print end
elapse_time = end-start
# dervers_time[PhantomJS] += elapse_time
print 'elapse for PhantomJS:%s' %elapse_time
# print 'nihao'
这段代码基本上和前面没什么区别,
重点需要关注的点有两个
一个是保存到指定文件夹里
一个是注意不能单独使用ip访问,要加上http