取得文章資料

async API.get_post(board: str, index: int) AsyncGenerator[tuple[list, list]]

Get the post data.

取得文章資料

Parameters:
  • board (str) – The PTT board name.

  • index (int) – The post index.

Returns:

AsyncGenerator[tuple[list, list]] – return an Asynchronous Generator that yields post data as a tuple(contents_html, post_replies)

-contents_html:

list of html string.

-post_replies:
list of dict that contains reply , dict like

{‘type’: ‘’, ‘author’: ‘’, ‘reply’: ‘’, ‘ip’: ‘’, ‘datetime’: ‘’}

範例

get_post() 回傳一個 Asynchronous Generator,每次回傳文章的”一頁”資料,直到全部載入為止。

我們可以用 async for 取得資料。

# ...
post_content = []
post_reply = []

post_data = await lib_pttea.get_post( "C_Chat" , 352036 )
async for page_data in post_data:
    content , reply = page_data

    post_content.extend(content)
    post_reply.extend(reply)