PTT
Submit
Submit
選擇語言
正體中文
简体中文
PTT
Python
[問題] 抓取留言
作者:
s1021412107
(阿宗)
2018-08-27 13:33:54
請問各位大大
小弟剛學爬蟲
想要抓取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
作者:
InfinityGate
(小鳥)
2018-08-27 16:38:00
把div.push裡面的span都抓下來啊爬蟲先摸熟chrome dev tools和html結構
作者:
qxpbyd
(qxpbyd)
2018-08-27 20:01:00
https://github.com/Truth0906/PTTLibrary
PTTLibrary裡的PTT.py 第1291行__getPost有別人寫好的API 可以參考
作者:
CodingMan
(程式俠)
2018-08-28 00:37:00
推資料結構可以看 Test.py 有比較清楚的範例
作者:
b24333666
(比飛笨)
2018-09-05 12:18:00
https://goo.gl/vV8QgY
我自己寫的應該會符合需求給你參考
繼續閱讀
[問題] 新增field到paradox database file
DK1225
[問題] 用Python 執行更新系統時間
fxsh1301
[問題] 爬蟲網頁後,想保留特定列資料[已解決]
wii8898333
[問題] pandas multiindex 取最後一筆
PTTleader
[問題] django html數據
kennysuper4
[問題] 請問list調整順序問題
CCT63
[問題] 學習create_trisurf 請教是否要這功能
jasonfghx
[問題] numpy broadcasting 矩陣特定位置運算
NMOSFET
[問題] leetcode上看到的問題和解法不是很懂..
ponwar87123
[問題] 宣告出問題
s1021412107
Links
booklink
Contact Us: admin [ a t ] ucptt.com