python爬糗事百科段子
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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(‘=============================================================================================================================‘)
以上是关于python爬糗事百科段子的主要内容,如果未能解决你的问题,请参考以下文章