一个研究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

本文介绍了如何使用Python的selenium库来实现微信投票的自动化。通过设置浏览器头部、滚动页面并点击特定元素,实现了投票过程的自动化。示例代码详细展示了定位并点击投票选项以及填写评论的操作。
2万+

被折叠的 条评论
为什么被折叠?



