声明:仅用于学习语法,请勿用于非法用途
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爬虫 爬取糗事百科
原创
©著作权归作者所有:来自51CTO博客作者ComK的原创作品,谢绝转载,否则将追究法律责任

提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
爬虫分页爬取糗事百科
利用urllib和正则匹配,单线程爬取糗事百科
爬虫 python 糗百 -
爬取糗事百科上的段子(BeautifulSoup)
爬取目标: 爬取糗事百科上的段子 过滤掉有图片的段子 实现每敲一次回车就显示一个段子的发布人,页数,内
糗事百科 Python 爬虫 加载 ico -
python3 爬虫之爬取糗事百科
闲着没事爬个糗事百科的笑话看看
爬虫 python urllib requests urllib3 -
Python爬取糗事百科所有段子
爬取糗事百科段子
糗事 百科段子