完成作业二:爬虫
This commit is contained in:
42
爬虫2.txt
Normal file
42
爬虫2.txt
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
# 人工智能数据服务 - 作业二
|
||||||
|
# 学号:你的学号
|
||||||
|
# 姓名:你的姓名
|
||||||
|
|
||||||
|
print("=" * 40)
|
||||||
|
print("学号:2509165016")
|
||||||
|
print("姓名:郭宇涵")
|
||||||
|
print("Hello, Git!")
|
||||||
|
print("我已经学会使用 Git 提交作业啦!")
|
||||||
|
print("=" * 40)
|
||||||
|
|
||||||
|
import requests
|
||||||
|
from bs4 import BeautifulSoup as bs
|
||||||
|
print('-------------')
|
||||||
|
url = 'https://www.baidu.com'
|
||||||
|
params = {'key':'value'}
|
||||||
|
|
||||||
|
response = requests.get(url,params=params)
|
||||||
|
|
||||||
|
print(response.status_code)
|
||||||
|
print('-------------')
|
||||||
|
html_content = response.text
|
||||||
|
print(html__content)
|
||||||
|
print('-------------')
|
||||||
|
soup = bs(html_content,'lxml')
|
||||||
|
print(soup)
|
||||||
|
print('-------------')
|
||||||
|
title = soup.find('title').string
|
||||||
|
print(title)
|
||||||
|
print('-------------')
|
||||||
|
links = soup.find_all('a')
|
||||||
|
print(links)
|
||||||
|
print('-------------')
|
||||||
|
for link in links:
|
||||||
|
# print("11111111")
|
||||||
|
print("链接:",linl.get('href'))
|
||||||
|
div_elements = soup.select('div.di')
|
||||||
|
print(div_elements)
|
||||||
|
for div in div_elements:
|
||||||
|
print('div:',div.text)
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user