get_post

PyPtt.API.get_post(self, board: str, aid: str | None = None, index: int | None = None, search_type: SearchType | None = None, search_condition: str | None = None, search_list: List[tuple] | None = None, query: bool = False) Dict

取得文章。

參數:
  • board (str) – 看板名稱。

  • aid (str) – 文章 AID,例如 '1TJH_XY0'

  • index (int) – 文章編號。

  • search_type (SearchType) – 搜尋類型,與 search_condition 搭配使用。

  • search_condition (str) – 搜尋條件,例如關鍵字或作者 ID。

  • search_list (List[Tuple]) – 多條件搜尋清單,每個元素為 (SearchType, condition)

  • query (bool) – 是否為查詢模式,不進入文章內容,僅取得列表資訊。

回傳:

Dict,文章內容。詳見 PostField

引發:

使用 AID 範例:

import PyPtt

ptt_bot = PyPtt.API()
try:
    # .. login ..
    post_info = ptt_bot.get_post('Python', aid='1TJH_XY0')
    # .. do something ..
finally:
    ptt_bot.logout()

使用 index 範例:

import PyPtt

ptt_bot = PyPtt.API()
try:
    # .. login ..
    post_info = ptt_bot.get_post('Python', index=1)
    # .. do something ..
finally:
    ptt_bot.logout()

使用搜尋範例:

import PyPtt

ptt_bot = PyPtt.API()
try:
    # .. login ..
    post_info = ptt_bot.get_post(
        'Python',
        index=1,
        search_list=[(PyPtt.SearchType.KEYWORD, 'PyPtt')]
    )
    # .. do something ..
finally:
    ptt_bot.logout()
更多範例參考 取得文章