Comments (4)
我嘗試出來是可以的,謝謝你!
from pyptt.
Hi @mu326345 你好
PyPtt 是模擬使用者實際登入 PTT 的操作,而開發也基於這個基礎上實作的,例如:使用者一次只能寄一封信。
所以 PyPtt 的 mail 功能一次也只能寄一封信。
所以如果存在使用者一次可以瀏覽十篇文章的操作方法,非常歡迎納入 PyPtt 的開發工作裡 😀
下面附上取得最新十篇文章的範例程式碼
import json
import PyPtt
if __name__ == '__main__':
ptt_bot = PyPtt.API()
try:
ptt_bot.login('Your PTT ID', 'Your PTT Password')
newest_index = ptt_bot.get_newest_index(PyPtt.NewIndex.BOARD, 'Python')
newest_range = 10
newest_count = 0
while newest_count < newest_range:
cur_index = newest_index - newest_count
newest_count += 1
post = ptt_bot.get_post('Python', index=cur_index)
if not post:
continue
if post["post_status"] != PyPtt.PostStatus.EXISTS:
continue
if not post["pass_format_check"]:
continue
if not post['content']:
continue
print(json.dumps(post, ensure_ascii=False, indent=4))
finally:
ptt_bot.logout()
請問你是想要文章列表的資訊嗎?我猜你好像是想要這個功能?
from pyptt.
是的,我是想要文章列表標題功能
照你的寫法不就是把前十篇的所有文章資訊包含文章內容抓下來了嗎,似乎沒有只查詢文章標題的做法?
from pyptt.
是把文章內容都抓下來了,之所以這樣是因為我誤會了你的描述「前十篇文章」而不是文章列表 or 標題。
目前的確是沒有取得文章列表標題的功能。
按照你的背景跟 issue 描述猜測,我認為你可以加上 query
參數。
query 模式,是指在文章列表按 Q 可以取得的所有資訊。
可以只取得文章標題與其相關資訊但沒有內容與其推文。
這樣當使用者點選某篇文章的時候,就可以使用 aid
來標定文章取得文章內容。
這樣一來,程式碼可以修改如下。
import json
import PyPtt
if __name__ == '__main__':
ptt_bot = PyPtt.API()
try:
ptt_bot.login('Your PTT ID', 'Your PTT Password')
newest_index = ptt_bot.get_newest_index(PyPtt.NewIndex.BOARD, 'Python')
newest_range = 10
newest_count = 0
while newest_count < newest_range:
cur_index = newest_index - newest_count
newest_count += 1
post = ptt_bot.get_post('Python', index=cur_index, query=True)
if not post:
continue
if post["post_status"] != PyPtt.PostStatus.EXISTS:
continue
if not post["pass_format_check"]:
continue
print(json.dumps(post, ensure_ascii=False, indent=4))
finally:
ptt_bot.logout()
祝順心。
from pyptt.
Related Issues (20)
- 新手問題(AttributeError: module 'PyPtt' has no attribute 'API') HOT 1
- 板主名單有特殊字元出錯 HOT 2
- 使用get_newest_index取book看板的newest_index不是最新的 HOT 3
- get_newest_index 用 search_list 搜特定關鍵字異常 HOT 7
- Dhggy
- 特定簽名檔會造成使用寄信功能後無法正常使用其他功能 HOT 2
- SingleLog 是否為必須的依賴? HOT 3
- 在抓我的最愛的時候,碰到分隔線就不繼續往下抓看板了 HOT 1
- 使用 PyPtt 的各位,有沒有意願加入 AI Labs
- 功能新增:匿名發文功能 HOT 8
- ConnectError: 連線失敗 HOT 3
- Failed to connect to PTT while PTT2 is Good HOT 1
- 編輯紅包袋 HOT 3
- code execution backdoor
- get_mail function will raise exception when mail without proper title HOT 3
- get_newest_index回傳2,但只有一篇文章(aid相同) HOT 1
- 新增功能;樂透功能 HOT 3
- comment 功能異常 HOT 1
- comment 功能異常 HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyptt.