首页 > 其他 > 详细

查看2dj的游客区是否有新公告

时间:2018-12-25 19:29:08      阅读:243      评论:0      收藏:0      [点我收藏+]

前几天想抢一下2dj的激活码(失败),又不想一次又一次的刷新来看

所以写了个python的迷你脚本来看游客区的公告是否有新帖

用的是正则来匹配帖子,

再比较帖子的数目判断是否有新帖

 

代码如下

 

技术分享图片
import re
from bs4 import BeautifulSoup
from urllib import request
from time import sleep
from tkinter import messagebox

def msgBox():
    warn = messagebox.showinfo("Hello", "Hello")
    print(warn)

url = "http://bbs4.2djgame.net/home/forum.php?mod=forumdisplay&fid=360&filter=typeid&typeid=911"
headers = {"User-Agent":"User-Agent:Mozilla/5.0"}
url_with_headers = request.Request(url, headers=headers)
html_doc = request.urlopen(url_with_headers)
soup = BeautifulSoup(html_doc, html.parser)
target_id = re.compile(r"normalthread_[0-9]+")
tbodys = soup.find_all(tbody, id=target_id)
pre = len(tbodys)

while True:
    url = "http://bbs4.2djgame.net/home/forum.php?mod=forumdisplay&fid=360&filter=typeid&typeid=911"
    headers = {"User-Agent":"User-Agent:Mozilla/5.0"}
    url_with_headers = request.Request(url, headers=headers)
    html_doc = request.urlopen(url_with_headers)
    soup = BeautifulSoup(html_doc, html.parser)
    target_id = re.compile(r"normalthread_[0-9]+")
    tbodys = soup.find_all(tbody, id=target_id)
    cur = len(tbodys)
    if cur == pre:
        print("No New")
    else:
        print("New One")
        msgBox()
        break
View Code

BTW,抢码失败,这个发码时间随意到令人发指。

查看2dj的游客区是否有新公告

原文:https://www.cnblogs.com/AcodingDg/p/10175492.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!