当前位置: 首页 > article >正文

爬虫xx网站论坛的帖子源码分享

import re
import time
from urllib import parse
import urllib

import requests

def updatepostinfo(startid,endid):    
    for num in range(int(startid),int(endid)+1):
        time.sleep(2)
        print(num)
        posturl="http:网站/detailnew.php?id="+str(num)
        postres=urllib.request.urlopen(posturl)
        postres=postres.read().decode() 
        print(postres)
        if "帖子不存在" in postres:
            continue
        elif "错误,帖子"  in postres:
            continue
        elif "该论坛不存在" in postres:
            continue
        elif "访问错误" in postres:
            continue
        elif "此帖审核中" in postres:
            continue
        elif "分版权限" in postres:
            continue
        else:
            posttitle=re.findall(r'<card id=\"main\" title=\"(.+?)\">',str(postres))
            postcontent=re.findall(r'name=\"content\" value=\"(.+?)\" />',str(postres))
            postcontent=postcontent[0]
            postauthid=re.findall(r"userid=(\d+)",str(postres))
            postauthid=postauthid[0]
            postforumid=re.findall(r"bid=(\d+)",str(postres))
            postforumid=postforumid[0]
            #下面存入对应字段到数据库
        

if __name__ == '__main__':
    updatepostinfo(1,292812334)

 

http://www.lryc.cn/news/2416433.html

相关文章:

  • FTPrush给Linux上传文件,LINUX CENTOS 7安装FTP服务器详细讲解(配图),FTPRUSH连接上传测试文件...
  • 【计算机网络】TCP和UDP的特点及区别
  • 高等数学 —— 函数的极限
  • MessageQueueMessage Pool—消息的读写、删除和回收
  • 编程算法常用术语中英对照
  • 正则表达式不包含指定字符
  • 着陆页如何设计?详解着陆页设计的5大要点及常见问题
  • nonzero用法
  • 【视频编码学习】AVS3参考软件HPM-4.1简单配置运行
  • 路由策略——route map
  • 非阻塞connect
  • EnableWindow()函数的应用
  • (28)CreateFont函数
  • C# CultureInfo 类之各国语言所对应的的区域性名称
  • JDBC元数据操作(一)-- DatabaseMetaData接口详解
  • 小菜和大鸟的编程故事之三:代码规范和重构意识
  • 数据库系统原理与应用教程(029)—— MySQL 的数据完整性(二):定义主键(primary key)
  • VMware虚拟机安装Ubuntu14.04.5-server详细图文教程
  • JS window对象 返回前一个浏览的页面 back()方法,加载 history 列表中的前一个 URL。 语法: window.history.back();
  • HDTUNE工具下载
  • python 爬取google总结
  • [PaddleGAN]人脸表情迁移-视频换脸
  • Android逆向之旅---破解一款永久免费网络访问工具
  • 关于同步电机的Ldq测量
  • 域名系统(Domain Name System,DNS)
  • 安奈特智能技术-半导体制造行业RFID解决方案
  • folsom版本horizon架构剖析
  • 分享35款最新出炉的免费个人博客模板
  • java中的强引用(Strong reference),软引用(SoftReference),弱引用(WeakReference),虚引用(PhantomReference)
  • session.setAttribute和request.setAttribute的区别