python爬蟲範例(mobile01 爬蟲電腦版為例)

import requests
from bs4 import BeautifulSoup

page = int(input("請輸入要擷取的頁數"))
for i in range(1,page+1):
    res = requests.get("https://www.mobile01.com/forumtopic.php?c=17&p="+ str(i))
    soup = BeautifulSoup(res.text,"html.parser")
    for title in soup.select(".topic_gen"):
        print ("==============")
        url = str(title.get('href'))
        print ("[標題]:"+title.text,"\n"+"https://www.mobile01.com/"+url)

留言

這個網誌中的熱門文章

教你如何看原始碼(以下載伊莉影片區的影片為例) (107/5/22更新)