网站开发公司 logo,培训总结心得体会,wordpress主题翻译,合肥网页设计哪家服务好最近闲的比较无聊#xff0c;于是想做一个自动star你的项目的爬虫玩玩。不然star数太低了#xff0c;也比较难看。思路是准备注册成批的github帐号#xff0c;然后挨个给你点star。STEP.1 工具准备我用的是python 2.7.10#xff0c;本次实验不需要下载依赖库#xff0c;用…最近闲的比较无聊于是想做一个自动star你的项目的爬虫玩玩。不然star数太低了也比较难看。思路是准备注册成批的github帐号然后挨个给你点star。STEP.1 工具准备我用的是python 2.7.10本次实验不需要下载依赖库用自带的就行了。import urllib2,urllib,re,timeSTEP.2 如何准备github帐号显然我们要star的话 帐号少说也得有个1000个吧。1000个帐号手动注册明显是不可能的所以我们得写个小程序来注册帐号。我们首先来调研一下github注册的过程。打开github-join我们填入如下信息用chrome开发者工具我们可以看到数据以post的形式发给了这个链接https://github.com/join。唯一还不明白的数据就是这个authenticity_token。但如果我们打开网页的源码会发现每一页都会有authenticity_token有时还有好几个而且还都不一样。那我们该发的是哪一个authenticity_token呢。事实上github每一个可供post的按钮都有token你在post的时候将离这个按钮最近的token发过去就行了。知道了这一点后我们就能开始写小程序了。STEP.3 github_join的编写class gitjoin:def __init__(self):cookies urllib2.HTTPCookieProcessor() #构造cookiesself.opener urllib2.build_opener(cookies)self.opener.addheaders [(User-agent, Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36),(Origin,https://github.com),(Accept,text/html,application/xhtmlxml,application/xml;q0.9,image/webp,*/*;q0.8),(Accept-Language,zh-CN,zh;q0.8),(Connection,keep-alive)] #请求头self.re_auth re.compile(authenticity_token[^]) #得到github token信息我们用一个叫gitjoin的类来封装我们的注册机。这里我们的正则表达式只用了一次只要匹配那个token就行了。然后我们需要获得token。这个token就是用来注册的。代码如下。def view(self):response self.opener.open(https://github.com/join)html response.read()print u正在登录joinprint u状态码为,response.getcode()token self.re_auth.findall(html)[0][41:-3]return token获得了token之后我们就可以开始注册了。def zhuce(self,token,login,email,password):self.formdata {utf-8:✓,authenticity_token:token,user[login]:login,user[email]:email,user[password]:password,source:form-home}data_encoded urllib.urlencode(self.formdata)print data_encodedresponse self.opener.open(https://github.com/join,data_encoded)print u正在注册print u状态码为,response.getcode(),u转到,response.geturl()注册完了就结束了吗?很明显没这么简单你注册完之后你的cookies保存了你的用户信息你这时是不能够继续注册的。你需要logout之后才能注册。这里logout我就不用chrome分析了。反正就是post一个数据给https://github.com/logout不过要记得加token(注意这里的token不是刚刚的注册token,我们需要重新获取它的logout token)。我直接上代码吧。这是获取logout tokendef view_index(self):response self.opener.open(https://github.com/)html response.read()token self.re_auth.findall(html)[0][41:-3]return token这是logoutdef logout(self,token):self.formdata {utf-8:✓,authenticity_token:token}data_encoded urllib.urlencode(self.formdata)response self.opener.open(https://github.com/logout,data_encoded)print u正在登出print u状态码为,response.getcode(),u转到,response.geturl()现在gitjoin类就已经写好了我们可以尝试注册一个账号了。signin gitjoin()token signin.view()signin.zhuce(token,pighasa100,pighasa100qq.com,pighasa1)执行代码后发现在github上也是能登录这个帐号的。说明我们成功了。下一步只需要批量生成帐号就行了。STEP.4 登录和点star然后关于登录和点star的问题。之前我在叙述如何注册的时候就说过了这里我就简要概括了。你们可以自己用chrome或者火狐或者wireshark去分析我这里就直接上代码了。这里是logindef login(self,token,usr,password):self.formdata {commit:Sign in,utf-8:✓,authenticity_token:token,login:usr,password:password}data_encoded urllib.urlencode(self.formdata)response self.opener.open(https://github.com/session,data_encoded)print u现在正在登陆,usr这里是stardef star(self,usrName,repoName):url .join([https://github.com/,usrName,/,repoName,/])response self.opener.open(url)html response.read()token self.re_auth.findall(html)[3][41:-3]formdata {utf-8:✓,authenticity_token:token}data_encoded urllib.urlencode(formdata)response self.opener.open(urlstar,data_encoded)STEP.5 疯狂star这一步还能干啥呢该干的都干了现在当然是疯狂的用刚刚注册好的帐号来点star。我们来看看效果。这是我的github页面很明显能看到一堆机器在点赞。不过我也是很怕被注意到然后被封掉的所以我设置的延时比较长点了一次赞之后要过6秒才能点下一次。这个项目po在这里githack。我在** github.py 这个文件里写了一个run函数你只需要调用run(你的id,你的仓库名,需要点赞的次数)就可以自动帮你点star了。喜欢的点一波喜欢