2017-04-25 37 views
0

我是一个完整的python新手和我的第一个项目,我试图从论坛帖子的特定用户刮,使用python scrip帖子,然后粘贴到一个原始文件。Scrape从一个特定用户使用美丽的汤的论坛帖子

我使用Python语言编码和美丽的汤编码库,但有一个打在滤波上的螺纹上的特定用户路障,

我应该如何筛选我的脚本保存为一个仅有帖子python中的特定用户? 这是我会再杀

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

+0

尝试使用'xpaths'和解析html将会非常容易 – anekix

回答

0

使用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