當前位置:菜譜大全網 - 菜譜大全 - 如何用python寫壹個爬蟲程序

如何用python寫壹個爬蟲程序

首先,您需要安裝requests和BeautifulSoup4。然後執行下面的代碼。importrequestsfrombs 4 import beautiful soup iurl = '。解析器')# Title H1 =湯。選擇(' # artibodyttitle ')[0]。text # Source time _ Source = soup . select('。時間源')[0]。text # Source origin = soup . select(' # artibodyp ')[0]。text . strip()# ori title = soup . select(' # artibodyp ')[66 . text . strip()# content raw _ content = soup . select(' # artibodyp ')[2:19]content =[]for paragraph raw _ content:content . append(paragraph . text . strip())@ '。加入(內容)#編輯AE =湯。選擇('。文章編輯器')[0]。短信夠了。