Python——开发一个自动化微信投票器【附代码实例方法】

一个研究Python实践,最近研究一个投票的东东,主要是想测试利用Python实现刷微信投票

本文纯粹为了记录一下 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()


 以上就是我的实践,更多可以参考:tp.gam7.com

转载于:https://www.cnblogs.com/xieyiyanjiu/p/10740039.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值