python 实现模拟登录网站并实现自动回复帖子

#-- coding:utf8 --
#!/usr/bin/env python 
#login 
import time
import requests 
import sys
import sys 
import json
import re
import threading
from bs4 import BeautifulSoup 
reload(sys)
sys.setdefaultencoding('gbk')
s=requests.Session() 
#login 
def login():
    auth_url = "http://www.xinxianwang.com/login/login.asp"
    values = { 
    "username":"****",
    "password":"******", 
    "k":"Fri Oct 23 2015 23:39:12 GMT+0800 (中国标准时间)40000"
    } 

    post_header ={ 
    "Referer":"http://www.xinxianwang.com/login", 
    "User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36", 
    "Accept-Encoding":"gzip, deflate", 
    "Accept-Language":"zh-CN,zh;q=0.8", 
    "Connection":"keep-alive" 
    }

    mm = s.post(auth_url, data=values,headers=post_header).content
    return mm   


def reply(topid):
    t=u"本群是新县最大的真实、严肃的单身交友群。本群的人员主要都是优秀的,素质高、学历高的新县单身男女。入群条件:1. 必须是单身。 2. 男20岁以上,女20岁以上适婚年龄。3. 在新县或者外地有稳定的工作。 4. 相信爱情,感情专一。 5. 以结婚为前提找对象,严肃!缘来如此1号群 99433323".encode("gbk")
    replyvalues={
    "title":"12332333",
    "ccooeditor":str(t),
    "setsign":1,
    "action":"save",
    "boardid":"126627",
    "topicid":topid,
    "page":3,
    "InfoID":6
    }
    fromdata={
    "postcontent":str(t),
    "auto":1
    }


    print s.post("http://www.xinxianwang.com/forum/reply.asp",data=replyvalues).content
#result topid
def result_topid():
    request=requests.get("http://www.xinxianwang.com/forum/today-1-1.html").content
#   print request
    topid=re.findall(r'thread-[0-9]+',request)  
    for id in topid:
        topid=int(id.split("-")[1])
        print topid
        reply(topid)    
        time.sleep(10)


def main():
    mm=login()
    if int(mm)==1:
        print "login success"
        result_topid()
main()

具体代码已经开源。具体思路就是通过chrome浏览器抓到post的参数。然后post具体的值就可以了。

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值