python爬糗事百科段子

#!/usr/bin/env python
# coding: UTF-8
# -*- coding: utf-8 -*-
import requests
from bs4 import BeautifulSoup
#import pandas
newurl='http://www.qiushibaike.com/text/page/1/'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2859.0 Safari/537.36'}
res = requests.get(newurl,headers=headers)
res.encoding = 'utf-8'
soup = BeautifulSoup(res.text,"html.parser")
a = soup.select('.content')
for i in a:
  print(i.select('span')[0].text.strip())
  print('=============================================================================================================================')
posted @ 2017-03-14 17:37  静渊居士  阅读(115)  评论(0编辑  收藏  举报