栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python html 爬虫 抓取论坛内容

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python html 爬虫 抓取论坛内容

找到论坛网址, 提取热门话题相关信息:

回复/浏览量

标题

发布时间

帖子链接

论坛热门榜:

效果如下:

代码实现如下:

import requests
from bs4 import BeautifulSoup
url = 'https://bbs.hupu.com/gp-hot'
res = requests.get(url)
content = res.text
soup = BeautifulSoup(content, 'html.parser')
all_body = soup.find_all(class_='bbs-sl-web-post-body')
for i in all_body:
    title = i.find('a')
    post_time = i.find(class_='post-time')
    reply = i.find(class_='post-datum')
    post_url1 = title['href']
    post_url = 'https://bbs.hupu.com' + post_url1
    print(
        '''Reply/Read -> 33[7;36;40m [{0}] 33[0m 
Title -> 33[7;36;1m  [{1}] 33[0m 
post_time -> [{2}]
post_url -> [{3}]
'''.format(reply.text, title.text, post_time.text, post_url))
    print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/869254.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号