1. 程式人生 > >python抓取部落格正文

python抓取部落格正文

import requests
from bs4 import BeautifulSoup
link = "http://www.santostang.com/2017/10/22/%E5%9B%BD%E5%86%85%E4%B8%8B%E8%BD%BDanaconda%E9%80%9F%E5%BA%A6%E6%85%A2%EF%BC%8C%E8%AF%B7%E4%BD%BF%E7%94%A8%E6%B8%85%E5%8D%8E%E9%95%9C%E5%83%8F/"
headers = {'User-Agent' : 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'
} r = requests.get(link, headers= headers) soup=BeautifulSoup(r.text, 'html.parser') for p in soup.select('.view-content'): #title = soup.select('.view-content p') #print(len(title)) #print(title[1]) print(p.text) ''' for i in range(len(t)): nn=list(t[i]) for j in range(len(nn)): if '
Linux' in nn[j]: print(nn[j]) '''