- 声明:仅用于学习语法,请勿用于非法用途
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
时间: 2024-10-10 16:28:53