From b1ca769724ca7e68528e81698bc83a71df3cf4d8 Mon Sep 17 00:00:00 2001 From: Qw37tgf5k <1879847326@qq.com> Date: Thu, 4 Nov 2021 16:36:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E4=BD=9C=E4=B8=9A3.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 001大作业3.0.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 001大作业3.0.py diff --git a/001大作业3.0.py b/001大作业3.0.py new file mode 100644 index 0000000..a0291c7 --- /dev/null +++ b/001大作业3.0.py @@ -0,0 +1,36 @@ +# @Time : 2021/11/1 22:09 +# @Author :wenkaic +# @File : 001python大作业 +# @Project : python爬虫 + + +import urllib.request +from bs4 import BeautifulSoup + +url = 'http://www.ddxs.com/doupocangqiong/' + +headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36 Edg/95.0.1020.40", +} + +# 请求对象定制 +request = urllib.request.Request(url=url, headers=headers) + +# 获取响应数据 +response = urllib.request.urlopen(request) + + +soup = BeautifulSoup(response.read().decode('utf-8'),'lxml') + +# 查询数据,返回列表 +bbs = soup.select('th,tr') + +#遍历列表 +for i in range(0,len(bbs)): + obj = bbs[i] + print(obj.get_text().strip()) + + + + +