2017-04-25 54 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