繁体   English   中英

使用美丽汤刮擦特定用户的论坛帖子

[英]Scrape Forum posts from a specific user using Beautiful soup

我是一个完整的python新手,对于我的第一个项目,我尝试使用python scrip在论坛主题上从特定用户处抓取帖子,然后将其粘贴到原始文件上。

我正在使用python编码语言和漂亮的汤编码库,但在过滤特定用户线程时遇到了障碍,

我应该如何过滤脚本以仅将特定用户的帖子保存在python中? 这是我将废弃的论坛

https://forums.spacebattles.com/threads/the-wizard-of-woah-and-irrational-methods-of-irrationality.337233/

像这样使用Xpath将用户名发布到论坛中

from bs4 import BeautifulSoup 
import requests 
page = requests.get('https://forums.spacebattles.com/threads/the-wizard-of-woah-and-irrational-methods-of-irrationality.337233/page-2')
page_source = page.content
soup = BeautifulSoup(page_source)
post = soup.body.find('div', 'messageContent')
user_name = post.find('div', 'attribution type')
if 'Harry Leferts' in user_name:
    '''save the post '''

我已经完成了从论坛获取单个帖子的操作,您可以使用find_all获取所有帖子

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM