> For the complete documentation index, see [llms.txt](https://clu.gitbook.io/python-web-crawler-note/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://clu.gitbook.io/python-web-crawler-note/25-dcardjin-ri-shi-da-re-men-wen-zhang.md).

# 2.5 Dcard今日十大熱門文章

這邊就簡單示範一下怎麼取得Dcard上的今日十大熱門文章.

```python
import requests
import re
from bs4 import BeautifulSoup


def main():
    dcard_topic_page = 'https://www.dcard.tw/f'
    resp = requests.get(dcard_topic_page)
    soup = BeautifulSoup(resp.text, 'html.parser')

    # ^ means "start with"
    topic_entry_pattern = '^PostEntry_container_'
    topic_title_pattern = 'strong'
    find_top10_hot_topic_title(soup, topic_entry_pattern, topic_title_pattern)


def find_top10_hot_topic_title(soup, topic_entry_pattern, topic_title_pattern):
    top_ten_topic = soup.find_all('div', {'class': re.compile(topic_entry_pattern)})
    i = 1
    for topic in top_ten_topic[:10]:
        print(str(i) + ': ' + topic.find(topic_title_pattern).text)
        i += 1


if __name__ == '__main__':
    main()
```

輸出如下:

```
1: 見到網美讓我哭了（更新）
2: 阿滴英文真的超讚!推爆
3: 我的搞笑「亡霉」日常生活 #圖多😂😂😂
4: 你們知道蛋放久會長毛嗎?
5: 超狂！對岸美妝收納賣家的售後服務
6: #黑特   為什麼要為了拍照發ig闖禁地？
7: 宣告違憲  媽媽卻告訴我別結婚
8: 女孩，不要有劇本💋
9: #圖 #貓 流浪貓真的要花很多時間
10: 想瘦下來要養成的幾個好習慣

Process finished with exit code 0
```

原始碼[點我](https://github.com/yotsuba1022/web-crawler-practice/blob/master/ch2/dcardCrawler.py)
