python-投票器

5402 ワード

一つの投票の東
本文は純粋にwebdriverがページボタンを直接操作する方法を記録するために
#!/usr/bin/python
#coding=utf-8
from selenium import webdriver
from selenium.webdriver import DesiredCapabilities
import sys,time
reload(sys)
sys.setdefaultencoding('utf-8')


desired_capabilities= DesiredCapabilities.PHANTOMJS.copy()
headers = {'Accept': '*/*',
'Accept-Language': 'en-US,en;q=0.8',
'Cache-Control': 'max-age=0',
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36',#     UA    
'Connection': 'keep-alive'
}
for key, value in headers.iteritems():
    desired_capabilities['phantomjs.page.customHeaders.{}'.format(key)] = value
desired_capabilities['phantomjs.page.customHeaders.User-Agent'] ='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'
driver= webdriver.PhantomJS(desired_capabilities=desired_capabilities)
url=''
driver.get(url)

js = "var q=document.body.scrollTop=100000"
for i in range(10):  
	driver.execute_script(js)  
	time.sleep(0.1) 

print driver.find_element_by_xpath('//*[@id="201290753"]/div[2]/ul/li[1]/p/span/span').text
driver.find_element_by_xpath('//*[@id="201290753"]/div[2]/ul/li[1]/p/span/span').click()
print driver.find_element_by_xpath('//*[@id="201290816"]/div[2]/ul/li[2]/p/span/span').text
driver.find_element_by_xpath('//*[@id="201290816"]/div[2]/ul/li[2]/p/span/span').click()

print driver.find_element_by_xpath('//*[@id="201290817"]/div[2]/ul/li[1]/p/span/span').text
driver.find_element_by_xpath('//*[@id="201290817"]/div[2]/ul/li[1]/p/span/span').click()
print driver.find_element_by_xpath('//*[@id="201290817"]/div[2]/ul/li[2]/p/span/span').text
driver.find_element_by_xpath('//*[@id="201290817"]/div[2]/ul/li[2]/p/span/span').click()
print driver.find_element_by_xpath('//*[@id="201290817"]/div[2]/ul/li[3]/p/span/span').text
driver.find_element_by_xpath('//*[@id="201290817"]/div[2]/ul/li[3]/p/span/span').click()

print driver.find_element_by_xpath('//*[@id="201290818"]/div[2]/ul/li[1]/p/span/span').text
driver.find_element_by_xpath('//*[@id="201290818"]/div[2]/ul/li[1]/p/span/span').click()
print driver.find_element_by_xpath('//*[@id="201290818"]/div[2]/ul/li[2]/p/span/span').text
driver.find_element_by_xpath('//*[@id="201290818"]/div[2]/ul/li[2]/p/span/span').click()
print driver.find_element_by_xpath('//*[@id="201290818"]/div[2]/ul/li[3]/p/span/span').text
driver.find_element_by_xpath('//*[@id="201290818"]/div[2]/ul/li[3]/p/span/span').click()
print driver.find_element_by_xpath('//*[@id="201290818"]/div[2]/ul/li[4]/p/span/span').text
driver.find_element_by_xpath('//*[@id="201290818"]/div[2]/ul/li[4]/p/span/span').click()


print driver.find_element_by_xpath('//*[@id="201290820"]/div[2]/ul/li[1]/p/span/span').text
driver.find_element_by_xpath('//*[@id="201290820"]/div[2]/ul/li[1]/p/span/span').click()
print driver.find_element_by_xpath('//*[@id="201290820"]/div[2]/ul/li[2]/p/span/span').text
driver.find_element_by_xpath('//*[@id="201290820"]/div[2]/ul/li[2]/p/span/span').click()


print driver.find_element_by_xpath('//*[@id="201290821"]/div[2]/ul/li[4]/p/span').text
driver.find_element_by_xpath('//*[@id="201290821"]/div[2]/ul/li[4]/p/span').click()
print 'zhesHi  11111 777777777777777777777'
print driver.find_element_by_xpath('//*[@id="201290822"]/div[2]/ul/li[1]/p/span/span').text
driver.find_element_by_xpath('//*[@id="201290822"]/div[2]/ul/li[1]/p/span/span').click()
print driver.find_element_by_xpath('//*[@id="201290822"]/div[2]/ul/li[2]/p/span/span').text
driver.find_element_by_xpath('//*[@id="201290822"]/div[2]/ul/li[2]/p/span/span').click()

print driver.find_element_by_xpath('//*[@id="201290824"]/div[2]/ul/li[2]/p/span/span').text
driver.find_element_by_xpath('//*[@id="201290824"]/div[2]/ul/li[2]/p/span/span').click()
print driver.find_element_by_xpath('//*[@id="201290825"]/div[2]/ul/li[2]/p/span').text
driver.find_element_by_xpath('//*[@id="201290825"]/div[2]/ul/li[2]/p/span').click()
print driver.find_element_by_xpath('//*[@id="201290826"]/div[2]/ul/li[2]/p/span').text
driver.find_element_by_xpath('//*[@id="201290826"]/div[2]/ul/li[2]/p/span').click()

print driver.find_element_by_xpath('//*[@id="201290841"]/div[2]/div/div/input').text
driver.find_element_by_xpath('//*[@id="201290841"]/div[2]/div/div/input').send_keys(u'    ')
print driver.find_element_by_xpath('//*[@id="201290841"]/div[2]/div/div/input').text

print driver.find_element_by_xpath('//*[@id="form_submit"]').text
driver.find_element_by_xpath('//*[@id="form_submit"]').click()

time.sleep(2)
print driver.page_source

driver.quit()