You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
765 B
35 lines
765 B
# @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())
|
|
|
|
|
|
|
|
|
|
|