[問題] 抓取留言
請問各位大大
小弟剛學爬蟲
想要抓取ptt裡的留言
但是我看網路只能抓留言的內容
推文、ID名稱、內容、時間怎麼同時抓下來
想要直接分類好推文還是噓文
Code如下:
import requests
from bs4 import BeautifulSoup
#所要擷取的網站網址
url = 'https://www.ptt.cc/bbs/movie/M.1535264750.A.3E3.html'
#建立回應
response = requests.get(url)
#印出網站原始碼
#print(response.text)
#將原始碼做整理
soup = BeautifulSoup(response.text, 'lxml')
#使用find_all()找尋特定目標
articles = soup.find_all('div', 'push')
#寫入檔案中
with open('movie_message.txt','w') as f:
for article in articles:
#去除掉冒號和左右的空白
messages = article.find('span','f3 push-content').getText().replace(':
','').strip()
print(messages)
f.write(messages + "\n")
https://i.imgur.com/dcD1cdz.jpg



--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 110.26.37.2
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1535348036.A.483.html
→
08/27 16:38,
6年前
, 1F
08/27 16:38, 1F
→
08/27 16:40,
6年前
, 2F
08/27 16:40, 2F
→
08/27 20:01,
6年前
, 3F
08/27 20:01, 3F
→
08/27 20:05,
6年前
, 4F
08/27 20:05, 4F
→
08/27 20:05,
6年前
, 5F
08/27 20:05, 5F
推
08/28 00:37,
6年前
, 6F
08/28 00:37, 6F
→
08/28 00:39,
6年前
, 7F
08/28 00:39, 7F
推
09/05 12:18,
6年前
, 8F
09/05 12:18, 8F
→
09/05 12:19,
6年前
, 9F
09/05 12:19, 9F
Python 近期熱門文章
PTT數位生活區 即時熱門文章