标签:python bs4 beautifulsoup scrapy 糗事百科
声明:仅用于学习语法,请勿用于非法用途
import urllib.request
import re
from bs4 import BeautifulSoup
# -*- coding:utf-8 -*-
url = ‘http://www.qiushibaike.com/hot/‘
user_agent=‘Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)‘
headers={‘User-Agent‘:user_agent}
request = urllib.request.Request(url=url,headers=headers)
response = urllib.request.urlopen(request)
bsobj = BeautifulSoup(response.read(), "html5lib")
#content = response.read().decode(‘utf-8‘)
#print(bsobj)
nameList = bsobj.find_all("div", {"class":"content"})
for name in nameList:
print(name.get_text())
input_enter = str(input())
if input_enter ==‘‘:
continue
本文出自 “净空蓝星” 博客,谢绝转载!
python beautifulsoup bs4爬虫 爬取糗事百科
标签:python bs4 beautifulsoup scrapy 糗事百科
原文地址:http://jingkonglanxing.blog.51cto.com/1152128/1906847