Giter Club home page Giter Club logo

Comments (4)

mu326345 avatar mu326345 commented on June 20, 2024 1

我嘗試出來是可以的,謝謝你!

from pyptt.

PttCodingMan avatar PttCodingMan commented on June 20, 2024

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.

mu326345 avatar mu326345 commented on June 20, 2024

是的,我是想要文章列表標題功能

照你的寫法不就是把前十篇的所有文章資訊包含文章內容抓下來了嗎,似乎沒有只查詢文章標題的做法?

from pyptt.

PttCodingMan avatar PttCodingMan commented on June 20, 2024

是把文章內容都抓下來了,之所以這樣是因為我誤會了你的描述「前十篇文章」而不是文章列表 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.