User-Profile-Image
hankin
  • 5
  • 首页
  • 分类
    • Windows
    • Web
    • VoIP
    • Virtualization
    • Trading
    • Smart Home
    • SEO
    • Security
    • Python
    • Program
    • PHP
    • OSX
    • OS
    • OpenSource
    • Nginx
    • MySQL
    • Mood
    • Linux
    • Life
    • Injection
    • Hosting
    • Exploits
    • CDN
  • 页面
    • About
  • 友链
    • 维酷科技
    • Tesra超算网络
Help?

Please contact us on our email for need any support

Support
  • 首页
    首页   ›   Program   ›   Python   ›   正文
Python

VeryCD灌水机-Python自动灌水脚本示例

2010-09-23 10:08:17
589  0 0

使用方法:
1.把username和passwd改成相应的东东
2.用python解释器执行脚本,自动在首页的所有资源后面跟帖支持楼主
`
想要了解灌水机原理的话:
1.学会python基本原理
2.学会正则表达式,网络脚本必备(也可以学beautifulsoup,写的代码更直观易懂,不过正则通用性强,总要学的)
3.学会html基本格式,理解获取网页的GET/POST机制
4.然后再看代码吧,这个脚本因为很简单,所以注释了一下

要实现每日灌水的话,linux下建个cron job,windows下计划任务,两周以后就升铜可以去那啥候补区闲逛了。

#!/usr/bin/env python
#coding:utf-8
#author:observer
#http://69.163.35.68/old
import urllib,urllib2,cookielib
import re,time,random

username = 'username'  #改成自己的用户名
passwd = 'password' #改成自己的密码
#这个就是发帖内容,任意改,会随机选择一条发帖
msg = [ '多谢楼主',
        'Mark',
        '正在找这个,谢谢',
        '谢谢分享',
    ]

def login():
    '''这个就是登录脚本'''
    print 'try to login...'

    #登录需要准备cookie
    cookie=cookielib.CookieJar()
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie), urllib2.HTTPHandler)
    urllib2.install_opener(opener)

    #先获取verycd的fk串,用于填表
    print '...getting login form...'
    loginform = urllib2.urlopen('http://secure.verycd.com/signin/*/http://www.verycd.com/').read()
    fk = re.compile(r'id="fk" value="(.*)"').findall(loginform)[0]

    #好的,现在填表
    postdata=urllib.urlencode({'username':username,
                           'password':passwd,
                           'continueURI':'http://www.verycd.com/',
                           'fk':fk,
                           'login_submit':'登录',
    })
    req = urllib2.Request(
        url = 'http://secure.verycd.com/signin/*/http://www.verycd.com/',
        data = postdata
    )

    #填header,伪装成正常浏览访问,这是一种写法,也可以用我之前那篇文章的写法,更有条理一点
    req.add_header('User-Agent','Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6')
    req.add_header('Accept','text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')
    req.add_header('Accept-Encoding','gzip,deflate')

    #交登录表,然后就登录成功了
    print '...login form submitted'
    result = urllib2.urlopen(req).read()
    print '...login succeed!'

def farm():
    '''这个就是灌水函数了'''
    #读取主页,获得主页的所有资源id
    res = urllib.urlopen('http://www.verycd.com').read()
    topics = re.compile(r'/topics/(\d+)').findall(res)
    topics = set(topics)
    print topics

    #对每一个获取的资源,回一贴支持楼主:)
    #语法和刚才交登录表差不多
    for topic in topics:
        url = 'http://www.verycd.com/topics/'+str(topic)+'/reply#fast-replay'
        print url
        postData = {
            'contents':random.choice(msg),
            'use_bbcode':'1',
            'tid':str(topic),
            'Action':'FolderCommentOperate:doReplyFolder'
        }
        postData = urllib.urlencode(postData)
        req = urllib2.Request(url = url, data = postData )
        kk = urllib2.urlopen(req).read()
        time.sleep(random.randint(1,10)) #随机等待一会再发贴

if __name__ == '__main__':
    login()
    farm()
评论 (0)

Click here to cancel reply.

欢迎您 游客  

    ProdigYu
    163文章 10评论 2点赞 80917浏览
    随机文章
    简易DNS快速设置(正反解析)
    10年前
    Apache修改默认连接数
    7年前
    CentOS安装VNC发生一个奇葩的错误
    7年前
    iptables查看NAT链命令
    1年前
    使用Bind 9 的DNS-views实现IP地址分区域解析
    11年前
    Tags
    Apache CentOS CMD DDOS Debian DNS FastCGI Google IIS IP iptables Linux Mac MySQL Nginx Opensource PHP Python Skill Spawn-FCGI SSH Ubuntu Vim VMware VPN web.py Windows 删除 命令 命令提示符 安装 开源 技巧 插件 漏洞 百度 系统 组件 终端 缓存 网络电话 脚本 自建 详解 错误
    Meta
    • Log in
    • Entries feed
    • Comments feed
    • WordPress.org
    Copyright © 2021
    Designed by hankin
    主页
    页面
    • About
    博主
    ProdigYu 管理员
    Something about myself
    163 文章 10 评论 80917 浏览
    测试
    测试