[爆卦]PTT 爬蟲 留言是什麼?優點缺點精華區懶人包

為什麼這篇PTT 爬蟲 留言鄉民發文收入到精華區:因為在PTT 爬蟲 留言這個討論話題中,有許多相關的文章在討論,這篇最有參考價值!作者s1021412107 (阿宗)看板Python標題[問題] 抓取留言時間Mon Aug 27 ...


請問各位大大
小弟剛學爬蟲
想要抓取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
https://i.imgur.com/qOreC31.jpg
https://i.imgur.com/cv3ixcj.jpg

--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 110.26.37.2
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1535348036.A.483.html
InfinityGate: 把div.push裡面的span都抓下來啊 08/27 16:38
InfinityGate: 爬蟲先摸熟chrome dev tools和html結構 08/27 16:40
qxpbyd: PTTLibrary裡的PTT.py 第1291行__getPost 08/27 20:05
qxpbyd: 有別人寫好的API 可以參考 08/27 20:05
CodingMan: 推 08/28 00:37
CodingMan: 資料結構可以看 Test.py 有比較清楚的範例 08/28 00:39
b24333666: https://goo.gl/vV8QgY 09/05 12:18
b24333666: 我自己寫的應該會符合需求給你參考 09/05 12:19

你可能也想看看

搜尋相關網站

A PHP Error was encountered

Severity: Core Warning

Message: Module 'imagick' already loaded

Filename: Unknown

Line Number: 0

Backtrace: