Bohrium
robot
新建

空间站广场

论文
Notebooks
比赛
课程
Apps
我的主页
我的Notebooks
我的论文库
我的足迹

我的工作空间

任务
节点
文件
数据集
镜像
项目
数据库
公开
53-57
python
python
donglikun@dp.tech
更新于 2024-07-09
推荐镜像 :Basic Image:bohrium-notebook:2023-04-07
推荐机型 :c2_m4_cpu
赞 1
Python53(v3)

09.高级特性(二):与高级扩展模块

代码
文本

53-图像处理库

〉 Pillow库

〉 图像处理步骤

〉 PIL图像操作

〉 小程序:PIL生成验证码

代码
文本

Pillow库

〉 Python里的图像处理库

PIL:Python Image Library

〉 功能强大,可以对图像做各种处理

缩放、裁剪、旋转、滤镜、文字、调色板等等

代码
文本

图像处理步骤

〉 打开图像

image.open(<路径+图像名+文件格式>)

Pillow库能自动根据文件内容确定格式

若图片在程序目录下,则不需要附带路径,直接将图像名+文件格式作为参数

〉 处理图像

image模块中提供了大量处理图像的方法

〉 存取或显示图像

im.show()
im.save(<文件名>)
代码
文本

PIL图像操作:缩略图

〉 thumbnail函数

thumbnail(size, Image.ANTIALIAS)

参数size为一个元组,指定生成缩略图的大小

直接对内存中的原图进行了修改, 但是修改完后的图片需要保存,处理后的图片不会被拉伸

代码
文本

PIL图像操作:模糊效果

代码
文本
[9]
!pip install pillow

#from PIL import Image, ImageFilter

# 打开一个jpg图像文件,注意是当前路径:
#im = Image.open('/bohr/Python53-rmz6/v1/test.jpg')
#im2.show()
# 应用模糊滤镜:
#im2 = im.filter(ImageFilter.BLUR)
#im2.save('/bohr/Python53-rmz6/v1/blur.jpg','jpeg')
#im2.show()

#使用matplotlib展示下原图和处理后的图像
from PIL import Image, ImageFilter
import matplotlib.pyplot as plt

# 打开一个jpg图像文件,注意是当前路径:
im = Image.open('/bohr/Python53-rmz6/v2/test.jpg')

# 展示原图:
plt.figure(figsize=(10, 5))

plt.subplot(1, 2, 1)
plt.title('Original Image')
plt.imshow(im)
plt.axis('off')

# 应用模糊滤镜:
im2 = im.filter(ImageFilter.BLUR)

# 保存结果图像:
im2.save('blur.jpg', 'jpeg')

# 展示处理后的图像:
plt.subplot(1, 2, 2)
plt.title('Blurred Image')
plt.imshow(im2)
plt.axis('off')

plt.show()
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: pillow in /opt/conda/lib/python3.8/site-packages (9.4.0)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
代码
文本

PIL图像操作:添加文字

代码
文本
[10]
#from PIL import Image,ImageDraw,ImageFont
#打开程序目录下的图片cat
#img = Image.open('/bohr/Python53-rmz6/v1/test.jpg')
#设置待添加文字大小为200,字体为宋体
#font = ImageFont.truetype('simsun.ttc',100)
#在img上创建可绘图对象draw
#draw = ImageDraw.Draw(img)
#添加红色文字“可爱的小猫”
#draw.text((100,10),'可爱的小猫'(255,0,0),font=font)
#保存照片
#img.save('cat1.jpg','jpeg')

#!pip install pillow
#!pip install matplotlib

from PIL import Image, ImageDraw, ImageFont
import matplotlib.pyplot as plt

# 打开程序目录下的图片
original_img = Image.open('/bohr/Python53-rmz6/v2/test.jpg')

# 创建原图的副本
img = original_img.copy()

# 设置待添加文字大小为100,字体为宋体
font = ImageFont.truetype('/bohr/Python53-rmz6/v2/simsun.ttf', 50)

# 在img上创建可绘图对象draw
draw = ImageDraw.Draw(img)

# 添加红色文字“可爱的小猫”
draw.text((100, 10), '可爱的小猫', fill=(255, 0, 0), font=font)

# 保存处理后的图像
img.save('cat1.jpg', 'jpeg')

# 使用matplotlib展示原图和处理后的图像
# 打开保存后的图像
processed_img = Image.open('cat1.jpg')

# 设置matplotlib来展示图像
plt.figure(figsize=(10, 5))

# 显示原图
plt.subplot(1, 2, 1)
plt.title('Original Image')
plt.imshow(original_img)
plt.axis('off')

# 显示处理后的图像
plt.subplot(1, 2, 2)
plt.title('Processed Image')
plt.imshow(processed_img)
plt.axis('off')

# 展示图像
plt.show()
代码
文本

小程序:PIL生成验证码

代码
文本
[2]
from PIL import Image, ImageDraw, ImageFont, ImageFilter

import random

# 随机字母:
def rndchar():
return chr(random.randint(65,90))
# 随机颜色1:
def rndcolor():
return(random.randint(64,255),\
random.randint(64,255),\
random.randint(64,255))
#随机颜色2:
def rndcolor2():
return(random.randint(32,127),\
random.randint(32,127),\
random.randint(32,127))
代码
文本
[5]
# 240 x 60:
#width=60 *4
#height =60
#image = Image.new('RGB',(width,height),(255,255,255))
# 创建Font对象:
#font = ImageFont.truetype('/bohr/Python53-rmz6/v3/Arial.ttf',36)
# 创建Draw对象:
#draw = ImageDraw.Draw(image)
# 填充每个像素:
#for x in range(width):
# for y in range(height):
# draw.point((x,y),fill=rndcolor())
# 输出文字:
#for t in range(4):
# draw.text((60 *t+ 10,10),rndchar(),font=font, fill=rndcolor2())
# 模糊:
#image = image.filter(ImageFilter.BLUR)
#image.save('code.jpg','jpeg')

from PIL import Image, ImageDraw, ImageFont, ImageFilter
import random
import string
import matplotlib.pyplot as plt

# 随机颜色1:
def rndcolor():
return (random.randint(64, 255), random.randint(64, 255), random.randint(64, 255))

# 随机颜色2:
def rndcolor2():
return (random.randint(32, 127), random.randint(32, 127), random.randint(32, 127))

# 随机字符:
def rndchar():
return random.choice(string.ascii_letters)

# 创建图像:
width = 60 * 4
height = 60
image = Image.new('RGB', (width, height), (255, 255, 255))

# 创建Font对象:
font_path = '/bohr/Python53-rmz6/v3/Arial.ttf' # 确保字体路径正确
font = ImageFont.truetype(font_path, 36)

# 创建Draw对象:
draw = ImageDraw.Draw(image)

# 填充每个像素:
for x in range(width):
for y in range(height):
draw.point((x, y), fill=rndcolor())

# 输出文字:
for t in range(4):
draw.text((60 * t + 10, 10), rndchar(), font=font, fill=rndcolor2())

# 模糊:
image = image.filter(ImageFilter.BLUR)
image_path = 'code.jpg'
image.save(image_path, 'jpeg')

# 使用matplotlib展示图片
image = Image.open(image_path)
plt.imshow(image)
plt.axis('off') # 隐藏坐标轴
plt.show()
代码
文本

54-Web服务框架

〉 Web应用

〉 框架的基本概念

〉 Flask框架

〉 表单插件Flask-WTF

代码
文本

〉 Web应用已经成为目前最热门的应用软件形式

〉 Web应用通过Web服务器提供服务,客户端采用浏览器或者遵循HTTP协议的客户端

〉 由于需要处理HTTP传输协议,很多web开发框架涌现

代码
文本

框架的基本概念

〉 什么是框架

Web服务器会处理与浏览器客户端交互的HTTP协议具体细节,但对具体内容的处理还需要自己编写代码

一个Web框架至少要具备处理浏览器客户端请求和服务端响应的能力

代码
文本

〉 框架的特性

· 路由

解析URL并找到对应的服务端文件或者Python服务器代码

· 模板

把服务端数据合并成HTML页面。

· 认证和授权

处理用户名、密码和权限

· Session

处理用户在多次请求之间需要存储的数据

〉 框架可能具备这些特性中的一种或多种

代码
文本

Flask框架

〉 Flask是一种非常容易上手的Python web开发框架,功能强大,支持很多专业Web 开发需要的扩展功能

Facebook认证和数据库集成

〉 只需要具备基本的Python开发技能,就可以开发出一个web应用来

alt

代码
文本

Flask框架:小例子

〉 一个Web服务器测试

在浏览器中访问http://127.0.0.1:5000/,这个服务器会返回一行文本

代码
文本
[11]
!pip install Flask
!pip install jinja2

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
return "Hello world!"
if __name__ == "__main__":
app.run()
已隐藏输出
代码
文本

在命令行中,导航到包含 app.py 的目录,然后运行:python app.py

你会看到类似以下的输出:Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

代码
文本

访问 Web 应用: 打开浏览器,访问 http://127.0.0.1:5000/,你应该会看到 “Hello world!” 这段文字

alt

代码
文本

表单插件Flask-WTF

〉 关于表单的扩展库

使用Flask-WTF时,每个表单都抽象成一个类

代码
文本
[17]
!pip install Flask
!pip install Flask-WTF
!pip install jinja2

from flask_wtf import Form
from wtforms import StringField
from wtforms.validators import DataRequired

class MyForm(Form):
user =StringField('Username',validators=[DataRequired()])

from flask import Flask, render_template

app =Flask(__name__)
app.secret_key='1234567'

@app.route('/login',methods=('GET','POST'))
def login():
form =MyForm()
if form.validate_on_submit():
# if form.user.data == 'admin':
if form.data['user']== 'admin':
return 'Admin login successfully!'
else:
return 'Wrong user!'
return render_template('login.html', form=form)

if __name__ == "__main__":
app.run()
已隐藏输出
代码
文本

代码中使用了 render_template 方法渲染 login.html 模板,需要在项目文件夹中创建一个 templates 文件夹,并在其中创建一个 login.html 文件。login.html 的内容如下图所示:

alt

最后运行在本地运行python app2.py

代码
文本

55-网络爬虫

〉 搜索引擎蜘蛛

〉 requests库

〉 Beautiful Soup

〉 爬虫的基本流程

代码
文本

搜索引擎蜘蛛

〉 爬虫是按照一定规则,自动地提取并保存网页中信息的程序

蜘蛛沿着网络抓取猎物

通过一个节点之后,顺着该节点的连线继续爬行到下一个节点,最终爬完整个网络的全部节点

〉 通过向网站发起请求获取资源,提取其中有用的信息

代码
文本

requests库

〉 Python实现的一个简单易用的HTTP库

支持HTTP持久连接和连接池、SSL证书验证、cookies处理、流式上传等

〉 向服务器发起请求并获取响应,完成访问网页的步骤

〉 简洁、容易理解,是最友好的网络爬虫库

代码
文本

〉 http请求类型

requests.request():构造一个请求

requests.get():获取HTML网页

requests.head():获取HTML网页头信息

requests.post():提交POST请求

requests.put():提交PUT请求

requests.patch():提交局部修改请求

requests.delete():提交删除请求

requests.options():获取http请求

〉 返回的是一个response对象

代码
文本

〉 response对象 包含服务器返回的所有信息,例如状态码、编码形式、文本内容等;也包含请求的request信息

· status_code:HTTP请求的返回状态

· text:HTTP响应内容的字符串形式

· content:HTTP响应内容的二进制形式

· encoding:(从HTTP header中)分析响应内容的编码方式

· apparent_encoding:(从内容中)分析响应内容的编码方式

代码
文本
[20]
!pip install requests

import requests
r= requests.get("http://www.baidu.com")
r.status_code
r.text
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: requests in /opt/conda/lib/python3.8/site-packages (2.28.2)
Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/lib/python3.8/site-packages (from requests) (2022.12.7)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /opt/conda/lib/python3.8/site-packages (from requests) (1.26.14)
Requirement already satisfied: idna<4,>=2.5 in /opt/conda/lib/python3.8/site-packages (from requests) (3.4)
Requirement already satisfied: charset-normalizer<4,>=2 in /opt/conda/lib/python3.8/site-packages (from requests) (3.0.1)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
'<!DOCTYPE html>\r\n<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>ç\x99¾åº¦ä¸\x80ä¸\x8bï¼\x8cä½\xa0å°±ç\x9f¥é\x81\x93</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value=ç\x99¾åº¦ä¸\x80ä¸\x8b class="bg s_btn"></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>æ\x96°é\x97»</a> <a href=http://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>å\x9c°å\x9b¾</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>è§\x86é¢\x91</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>è´´å\x90§</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&amp;tpl=mn&amp;u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb>ç\x99»å½\x95</a> </noscript> <script>document.write(\'<a href="http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u=\'+ encodeURIComponent(window.location.href+ (window.location.search === "" ? "?" : "&")+ "bdorz_come=1")+ \'" name="tj_login" class="lb">ç\x99»å½\x95</a>\');</script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;">æ\x9b´å¤\x9a产å\x93\x81</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>å\x85³äº\x8eç\x99¾åº¦</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>&copy;2017&nbsp;Baidu&nbsp;<a href=http://www.baidu.com/duty/>使ç\x94¨ç\x99¾åº¦å\x89\x8då¿\x85读</a>&nbsp; <a href=http://jianyi.baidu.com/ class=cp-feedback>æ\x84\x8fè§\x81å\x8f\x8dé¦\x88</a>&nbsp;京ICPè¯\x81030173å\x8f·&nbsp; <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>\r\n'
代码
文本
[21]
r.encoding

r.apparent_encoding

r.encoding = "utf-8"
r.text
'<!DOCTYPE html>\r\n<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>百度一下,你就知道</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value=百度一下 class="bg s_btn"></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>新闻</a> <a href=http://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>地图</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>视频</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>贴吧</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&amp;tpl=mn&amp;u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb>登录</a> </noscript> <script>document.write(\'<a href="http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u=\'+ encodeURIComponent(window.location.href+ (window.location.search === "" ? "?" : "&")+ "bdorz_come=1")+ \'" name="tj_login" class="lb">登录</a>\');</script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;">更多产品</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>关于百度</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>&copy;2017&nbsp;Baidu&nbsp;<a href=http://www.baidu.com/duty/>使用百度前必读</a>&nbsp; <a href=http://jianyi.baidu.com/ class=cp-feedback>意见反馈</a>&nbsp;京ICP证030173号&nbsp; <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>\r\n'
代码
文本

〉 定制请求头

requests的请求接口有一个名为headers的参数,向它传递一个字典来完成请求头定制

〉 设置代理

一些网站设置了同一IP访问次数的限制,可以在发送请求时指定proxies参数来替换代理,解决这一问题

代码
文本
[24]
#proxies ={
# "http":"http://10.10.10.10:1010",
# "https":"http://10.11.10.14:1011",
# }
#r = requests.get(url,proxies =proxies)

import requests

url = "http://www.baidu.com"

proxies = {
"http": "http://10.10.10.10:1010",
"https": "http://10.11.10.14:1011",
}

# 使用代理发送请求
r = requests.get(url, proxies=proxies)

# 输出状态码和响应内容
print(f"Status Code: {r.status_code}")
print(f"Response Text: {r.text[:500]}...") # 只打印前500个字符以避免输出过长
---------------------------------------------------------------------------
TimeoutError                              Traceback (most recent call last)
File /opt/conda/lib/python3.8/site-packages/urllib3/connection.py:174, in HTTPConnection._new_conn(self)
    173 try:
--> 174     conn = connection.create_connection(
    175         (self._dns_host, self.port), self.timeout, **extra_kw
    176     )
    178 except SocketTimeout:

File /opt/conda/lib/python3.8/site-packages/urllib3/util/connection.py:95, in create_connection(address, timeout, source_address, socket_options)
     94 if err is not None:
---> 95     raise err
     97 raise socket.error("getaddrinfo returns an empty list")

File /opt/conda/lib/python3.8/site-packages/urllib3/util/connection.py:85, in create_connection(address, timeout, source_address, socket_options)
     84     sock.bind(source_address)
---> 85 sock.connect(sa)
     86 return sock

TimeoutError: [Errno 110] Connection timed out

During handling of the above exception, another exception occurred:

NewConnectionError                        Traceback (most recent call last)
File /opt/conda/lib/python3.8/site-packages/urllib3/connectionpool.py:703, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    702 # Make the request on the httplib connection object.
--> 703 httplib_response = self._make_request(
    704     conn,
    705     method,
    706     url,
    707     timeout=timeout_obj,
    708     body=body,
    709     headers=headers,
    710     chunked=chunked,
    711 )
    713 # If we're going to release the connection in ``finally:``, then
    714 # the response doesn't need to know about the connection. Otherwise
    715 # it will also try to release it and we'll have a double-release
    716 # mess.

File /opt/conda/lib/python3.8/site-packages/urllib3/connectionpool.py:398, in HTTPConnectionPool._make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
    397     else:
--> 398         conn.request(method, url, **httplib_request_kw)
    400 # We are swallowing BrokenPipeError (errno.EPIPE) since the server is
    401 # legitimately able to close the connection after sending a valid response.
    402 # With this behaviour, the received response is still readable.

File /opt/conda/lib/python3.8/site-packages/urllib3/connection.py:239, in HTTPConnection.request(self, method, url, body, headers)
    238     headers["User-Agent"] = _get_default_user_agent()
--> 239 super(HTTPConnection, self).request(method, url, body=body, headers=headers)

File /opt/conda/lib/python3.8/http/client.py:1256, in HTTPConnection.request(self, method, url, body, headers, encode_chunked)
   1255 """Send a complete request to the server."""
-> 1256 self._send_request(method, url, body, headers, encode_chunked)

File /opt/conda/lib/python3.8/http/client.py:1302, in HTTPConnection._send_request(self, method, url, body, headers, encode_chunked)
   1301     body = _encode(body, 'body')
-> 1302 self.endheaders(body, encode_chunked=encode_chunked)

File /opt/conda/lib/python3.8/http/client.py:1251, in HTTPConnection.endheaders(self, message_body, encode_chunked)
   1250     raise CannotSendHeader()
-> 1251 self._send_output(message_body, encode_chunked=encode_chunked)

File /opt/conda/lib/python3.8/http/client.py:1011, in HTTPConnection._send_output(self, message_body, encode_chunked)
   1010 del self._buffer[:]
-> 1011 self.send(msg)
   1013 if message_body is not None:
   1014 
   1015     # create a consistent interface to message_body

File /opt/conda/lib/python3.8/http/client.py:951, in HTTPConnection.send(self, data)
    950 if self.auto_open:
--> 951     self.connect()
    952 else:

File /opt/conda/lib/python3.8/site-packages/urllib3/connection.py:205, in HTTPConnection.connect(self)
    204 def connect(self):
--> 205     conn = self._new_conn()
    206     self._prepare_conn(conn)

File /opt/conda/lib/python3.8/site-packages/urllib3/connection.py:186, in HTTPConnection._new_conn(self)
    185 except SocketError as e:
--> 186     raise NewConnectionError(
    187         self, "Failed to establish a new connection: %s" % e
    188     )
    190 return conn

NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f496c9a07c0>: Failed to establish a new connection: [Errno 110] Connection timed out

During handling of the above exception, another exception occurred:

MaxRetryError                             Traceback (most recent call last)
File /opt/conda/lib/python3.8/site-packages/requests/adapters.py:489, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)
    488 if not chunked:
--> 489     resp = conn.urlopen(
    490         method=request.method,
    491         url=url,
    492         body=request.body,
    493         headers=request.headers,
    494         redirect=False,
    495         assert_same_host=False,
    496         preload_content=False,
    497         decode_content=False,
    498         retries=self.max_retries,
    499         timeout=timeout,
    500     )
    502 # Send the request.
    503 else:

File /opt/conda/lib/python3.8/site-packages/urllib3/connectionpool.py:787, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    785     e = ProtocolError("Connection aborted.", e)
--> 787 retries = retries.increment(
    788     method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
    789 )
    790 retries.sleep()

File /opt/conda/lib/python3.8/site-packages/urllib3/util/retry.py:592, in Retry.increment(self, method, url, response, error, _pool, _stacktrace)
    591 if new_retry.is_exhausted():
--> 592     raise MaxRetryError(_pool, url, error or ResponseError(cause))
    594 log.debug("Incremented Retry for (url='%s'): %r", url, new_retry)

MaxRetryError: HTTPConnectionPool(host='10.10.10.10', port=1010): Max retries exceeded with url: http://www.baidu.com/ (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f496c9a07c0>: Failed to establish a new connection: [Errno 110] Connection timed out')))

During handling of the above exception, another exception occurred:

ProxyError                                Traceback (most recent call last)
Cell In[24], line 17
     11 proxies = {
     12     "http": "http://10.10.10.10:1010",
     13     "https": "http://10.11.10.14:1011",
     14 }
     16 # 使用代理发送请求
---> 17 r = requests.get(url, proxies=proxies)
     19 # 输出状态码和响应内容
     20 print(f"Status Code: {r.status_code}")

File /opt/conda/lib/python3.8/site-packages/requests/api.py:73, in get(url, params, **kwargs)
     62 def get(url, params=None, **kwargs):
     63     r"""Sends a GET request.
     64 
     65     :param url: URL for the new :class:`Request` object.
   (...)
     70     :rtype: requests.Response
     71     """
---> 73     return request("get", url, params=params, **kwargs)

File /opt/conda/lib/python3.8/site-packages/requests/api.py:59, in request(method, url, **kwargs)
     55 # By using the 'with' statement we are sure the session is closed, thus we
     56 # avoid leaving sockets open which can trigger a ResourceWarning in some
     57 # cases, and look like a memory leak in others.
     58 with sessions.Session() as session:
---> 59     return session.request(method=method, url=url, **kwargs)

File /opt/conda/lib/python3.8/site-packages/requests/sessions.py:587, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    582 send_kwargs = {
    583     "timeout": timeout,
    584     "allow_redirects": allow_redirects,
    585 }
    586 send_kwargs.update(settings)
--> 587 resp = self.send(prep, **send_kwargs)
    589 return resp

File /opt/conda/lib/python3.8/site-packages/requests/sessions.py:701, in Session.send(self, request, **kwargs)
    698 start = preferred_clock()
    700 # Send the request
--> 701 r = adapter.send(request, **kwargs)
    703 # Total elapsed time of the request (approximately)
    704 elapsed = preferred_clock() - start

File /opt/conda/lib/python3.8/site-packages/requests/adapters.py:559, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)
    556     raise RetryError(e, request=request)
    558 if isinstance(e.reason, _ProxyError):
--> 559     raise ProxyError(e, request=request)
    561 if isinstance(e.reason, _SSLError):
    562     # This branch is for urllib3 v1.22 and later.
    563     raise SSLError(e, request=request)

ProxyError: HTTPConnectionPool(host='10.10.10.10', port=1010): Max retries exceeded with url: http://www.baidu.com/ (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f496c9a07c0>: Failed to establish a new connection: [Errno 110] Connection timed out')))
代码
文本

Beautiful Soup

〉 页面解析器

使用requests库下载了网页并转换成字符串后,需要一个解析器来处理HTML和XML,解析页面格式,提取有用的信息

〉 解析器类型

alt

代码
文本

〉 搜索方法

find_all(name, attrs, recursive, string,**kwargs)

返回文档中符合条件的所有tag,是一个列表

find(name, attrs, recursive, string,**kwargs)

相当于find_all()中limit = 1,返回一个结果

name:对标签名称的检索字符串

attrs: 对标签属性值的检索字符串

recursive: 是否对子节点全部检索,默认为True

string: <>...</> 中检索字符串

**kwargs:关键词参数列表

代码
文本

爬虫的基本流程

〉 分析网页结构

alt

代码
文本

〉 爬取页面

通过requests库向目标站点发送请求,若对方服务器正常响应,能够收到一个response对象,它包含了服务器返回的所有信息

代码
文本
[25]
import requests
url = "http://news.qq.com/"
r=requests.get(url,timeout =30)
print(r.text)
<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <title>优质资讯推荐_腾讯网</title>
<meta name="keywords" content="资讯,新闻,财经,房产,视频,NBA,科技,腾讯网,腾讯,QQ,Tencent">
<meta name="Description" content="腾讯网从2003年创立至今,已经成为集新闻信息,区域垂直生活服务、社会化媒体资讯和产品为一体的互联网媒体平台。腾讯网下设新闻、科技、财经、娱乐、体育、汽车、时尚等多个频道,充分满足用户对不同类型资讯的需求。同时专注不同领域内容,打造精品栏目,并顺应技术发展趋势,推出网络直播等创新形式,改变了用...">
<meta name="baidu-site-verification" content="code-mzfngMK684" />
    <meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<link rel="shortcut icon" href="https://mat1.gtimg.com/qqcdn/qqindex2021/favicon.ico">
<link rel="dns-prefetch" href="//mat1.gtimg.com">
<link rel="dns-prefetch" href="//pacaio.match.qq.com">
<link rel="dns-prefetch" href="//i.news.qq.com">
<script src="https://mat1.gtimg.com/qqcdn/qqindex2021/common-static/20240515201444/core3-37-1.min.js"></script>
<script>
  try {
    if ('scrollRestoration' in window.history) {
      window.history.scrollRestoration = 'manual';
    }
  } catch {}
</script>
<script>
  window.channelInfo = {"isEdu":false,"channelKey":"news","channelType":"channel","channelConfig":{"channelRight":[{"_auto_id":"1","channel_name_en":"news","modules":"{\"moduleList\":[{\"title\":\"热点榜\",\"id\":\"hot_rank_list\"},{\"title\":\"精选视频\",\"id\":\"video_album\",\"videoType\":\"tag\",\"videoId\":\"aUepxrtchGM=\",\"isSticky\":0},{\"title\":\"下载条\",\"id\":\"download_banner\",\"isSticky\":0},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"ad_block\",\"path\":\"news_tuiguang_2023.htm\",\"isSticky\":0},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"l_qq_com\",\"path\":\"QQcom_all_Rectangle-1|QQcom_all_Rectangle-2\",\"isSticky\":1}]}"},{"_auto_id":"2","channel_name_en":"local","modules":"{\"moduleList\":[{\"title\":\"精选视频\",\"id\":\"video_album\",\"videoType\":\"tag\",\"videoId\":\"aUepxrtchGM=\"},{\"title\":\"下载条\",\"id\":\"download_banner\",\"isSticky\":1},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":1}]}"},{"_auto_id":"3","channel_name_en":"finance","modules":"{\"moduleList\":[{\"title\":\"精选视频\",\"id\":\"video_album\",\"videoType\":\"cid\",\"videoId\":\"mzc003o3p0wi5fe\",\"isSticky\":0},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"ad_block\",\"path\":\"test/finance_huiyi.htm\",\"isSticky\":0},{\"title\":\"股市指数看板\",\"id\":\"stock\",\"isSticky\":0},{\"title\":\"下载条\",\"id\":\"download_banner\",\"isSticky\":1},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":1}]}"},{"_auto_id":"4","channel_name_en":"tech","modules":"{\"moduleList\":[{\"title\":\"精选视频\",\"id\":\"video_album\",\"videoType\":\"tag\",\"videoId\":\"aUeoyrtcgWo=\"},{\"title\":\"下载条\",\"id\":\"download_banner\",\"isSticky\":1},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":1}]}"},{"_auto_id":"5","channel_name_en":"wwqy","modules":"{\"moduleList\":[{\"title\":\"精选视频\",\"id\":\"video_album\",\"videoType\":\"cid\",\"videoId\":\"mzc003rreymhpay\",\"isSticky\":0},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":0},{\"title\":\"下载条\",\"id\":\"download_banner\",\"isSticky\":1},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"game_block\",\"path\":\"ch_gameRank_2023.htm\",\"isSticky\":1}]}"},{"_auto_id":"6","channel_name_en":"ent","modules":"{\"moduleList\":[{\"title\":\"精选视频\",\"id\":\"video_album\",\"videoType\":\"vids\",\"videoId\":\"f35245xghir,c3527btmjty,n35443uwvjr,r3542iu6lsm,l3544elvn3g\"},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":0},{\"title\":\"下载条\",\"id\":\"download_banner\",\"isSticky\":0},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"ad_block\",\"path\":\"ent_tuiguang.htm\",\"isSticky\":0},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"l_qq_com\",\"path\":\"QQcom_all_Rectangle-1|QQcom_all_Rectangle-2\",\"isSticky\":1}]}"},{"_auto_id":"7","channel_name_en":"esport","modules":"{\"moduleList\":[{\"title\":\"精选视频\",\"id\":\"video_album\",\"videoType\":\"tag\",\"videoId\":\"aE6qx7Jfj2E=\"},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"game_block\",\"path\":\"ch_gameRank_2023.htm\",\"isSticky\":0},{\"title\":\"下载条\",\"id\":\"download_banner\",\"isSticky\":1},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":1}]}"},{"_auto_id":"8","channel_name_en":"world","modules":"{\"moduleList\":[{\"title\":\"精选视频\",\"id\":\"video_album\",\"videoType\":\"tag\",\"videoId\":\"aE6pwrlajms=\",\"isSticky\":0},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"l_qq_com\",\"path\":\"QQcom_all_Rectangle-1\",\"isSticky\":0},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"l_qq_com\",\"path\":\"QQcom_all_Rectangle-2\",\"isSticky\":0},{\"title\":\"下载条\",\"id\":\"download_banner\",\"isSticky\":1},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":1}]}"},{"_auto_id":"9","channel_name_en":"myfz","modules":"{\"moduleList\":[{\"title\":\"精选视频\",\"id\":\"video_album\",\"videoType\":\"cid\",\"videoId\":\"mzc0030co7rkoy3\",\"isSticky\":0},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":0},{\"title\":\"下载条\",\"id\":\"download_banner\",\"isSticky\":1},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"game_block\",\"path\":\"ch_gameRank_2023.htm\",\"isSticky\":1}]}"},{"_auto_id":"10","channel_name_en":"milite","modules":"{\"moduleList\":[{\"title\":\"精选视频\",\"id\":\"video_album\",\"videoType\":\"tag\",\"videoId\":\"aUepy7pdgmM=\",\"isSticky\":0},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"l_qq_com\",\"path\":\"QQcom_all_Rectangle-1|QQcom_all_Rectangle-2\",\"isSticky\":0},{\"title\":\"下载条\",\"id\":\"download_banner\",\"isSticky\":1},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":1}]}"},{"_auto_id":"11","channel_name_en":"games","modules":"{\"moduleList\":[{\"title\":\"精选视频\",\"id\":\"video_album\",\"videoType\":\"tag\",\"videoId\":\"aE6qx7Jfj2E=\",\"isSticky\":0},{\"title\":\"热门游戏\",\"id\":\"recommend_game\",\"isSticky\":0},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"ad_block\",\"path\":\"games_tuiguang.htm\",\"isSticky\":0},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"game_block\",\"path\":\"ch_gameRank_2023.htm\",\"isSticky\":0},{\"title\":\"下载条\",\"id\":\"download_banner\",\"isSticky\":1},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":1}]}"},{"_auto_id":"12","channel_name_en":"cul","modules":"{\"moduleList\":[{\"title\":\"精选视频\",\"id\":\"video_album\",\"videoType\":\"vids\",\"videoId\":\"g35116nw2je,z3510e3izi9,l3511iy77cn,e3511vujdli,o3510fc3jo1\",\"isSticky\":0},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":0},{\"title\":\"下载条\",\"id\":\"download_banner\",\"isSticky\":1},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"l_qq_com\",\"path\":\"QQcom_all_Rectangle\",\"isSticky\":1},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"ad_block\",\"path\":\"cul_tuiguang.htm\",\"isSticky\":1}]}"},{"_auto_id":"13","channel_name_en":"health","modules":"{\"moduleList\":[{\"title\":\"精选视频\",\"id\":\"video_album\",\"videoType\":\"tag\",\"videoId\":\"aEGsxLNdhWU=\",\"isSticky\":0},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"l_qq_com\",\"path\":\"QQcom_all_Rectangle-1\",\"isSticky\":0},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"l_qq_com\",\"path\":\"QQcom_all_Rectangle-2\",\"isSticky\":0},{\"title\":\"下载条\",\"id\":\"download_banner\",\"isSticky\":1},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":1}]}"},{"_auto_id":"14","channel_name_en":"auto","modules":"{\"moduleList\":[{\"title\":\"精选视频\",\"id\":\"video_album\",\"videoType\":\"tag\",\"videoId\":\"aUepxLNbg2A=\",\"isSticky\":0},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":0},{\"title\":\"下载条\",\"id\":\"download_banner\",\"isSticky\":1},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"ad_block\",\"path\":\"auto_tuiguang.htm\",\"isSticky\":1}]}"},{"_auto_id":"15","channel_name_en":"house","modules":"{\"moduleList\":[{\"title\":\"精选视频\",\"id\":\"video_album\",\"videoType\":\"tag\",\"videoId\":\"aUeoyrlZg2s=\",\"isSticky\":0},{\"title\":\"下载条\",\"id\":\"download_banner\",\"isSticky\":1},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":1}]}"},{"_auto_id":"16","channel_name_en":"finance_licai","modules":"{\"moduleList\":[{\"title\":\"精选视频\",\"id\":\"video_album\",\"videoType\":\"cid\",\"videoId\":\"mzc003o3p0wi5fe\",\"isSticky\":0},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":0},{\"title\":\"下载条\",\"id\":\"download_banner\",\"isSticky\":1},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"ad_block\",\"path\":\"licai_topnews.htm\",\"isSticky\":1}]}"},{"_auto_id":"17","channel_name_en":"finance_stock","modules":"{\"moduleList\":[{\"title\":\"精选视频\",\"id\":\"video_album\",\"videoType\":\"cid\",\"videoId\":\"mzc003o3p0wi5fe\",\"isSticky\":0},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":0},{\"title\":\"下载条\",\"id\":\"download_banner\",\"isSticky\":1},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"ad_block\",\"path\":\"licai_topnews.htm\",\"isSticky\":1}]}"},{"_auto_id":"18","channel_name_en":"history","modules":"{\"moduleList\":[{\"title\":\"精选视频\",\"id\":\"video_album\",\"videoType\":\"vids\",\"videoId\":\"g35116nw2je,z3510e3izi9,l3511iy77cn,e3511vujdli,o3510fc3jo1\",\"isSticky\":0},{\"title\":\"下载条\",\"id\":\"download_banner\",\"isSticky\":1},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":1}]}"},{"_auto_id":"19","channel_name_en":"baby","modules":"{\"moduleList\":[{\"title\":\"精选视频\",\"id\":\"video_album\",\"videoType\":\"cid\",\"videoId\":\"mzc003dzcgg3h4o\",\"isSticky\":0},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"ad_block\",\"path\":\"baby_tuiguang.htm\",\"isSticky\":0},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"l_qq_com\",\"path\":\"Baby_Rectangle_2019\",\"isSticky\":0},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"l_qq_com\",\"path\":\"QQcom_all_Rectangle\",\"isSticky\":0},{\"title\":\"下载条\",\"id\":\"download_banner\",\"isSticky\":1},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":1}]}"},{"_auto_id":"20","channel_name_en":"digi","modules":"{\"moduleList\":[{\"title\":\"精选视频\",\"id\":\"video_album\",\"videoType\":\"vids\",\"videoId\":\"e354619j6tb,s1484zr32j9,f1485z40a8l,x1199wotxx6,e3546v1zrdi\",\"isSticky\":0},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"l_qq_com\",\"path\":\"QQcom_all_Rectangle-1|QQcom_all_Rectangle-2\",\"isSticky\":0},{\"title\":\"下载条\",\"id\":\"download_banner\",\"isSticky\":1},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":1}]}"},{"_auto_id":"21","channel_name_en":"chupin","modules":"{\"moduleList\":[{\"title\":\"精选视频\",\"id\":\"video_album\",\"videoType\":\"vids\",\"videoId\":\"g35116nw2je,z3510e3izi9,l3511iy77cn,e3511vujdli,o3510fc3jo1\",\"isSticky\":0},{\"title\":\"下载条\",\"id\":\"download_banner\",\"isSticky\":1},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":1}]}"},{"_auto_id":"22","channel_name_en":"kepu","modules":"{\"moduleList\":[{\"title\":\"精选视频\",\"id\":\"video_album\",\"videoType\":\"tag\",\"videoId\":\"aEGswbJah2Y=\",\"isSticky\":0},{\"title\":\"下载条\",\"id\":\"download_banner\",\"isSticky\":1},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":1}]}"},{"_auto_id":"23","channel_name_en":"football","modules":"{\"moduleList\":[{\"title\":\"精选视频\",\"id\":\"video_album\",\"videoType\":\"tag\",\"videoId\":\"aUWsy7NfgWs=\",\"isSticky\":0},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"l_qq_com\",\"path\":\"QQcom_all_Rectangle-1|QQcom_all_Rectangle-2\",\"isSticky\":0},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"l_qq_com\",\"path\":\"Sports_Rectangle2\",\"isSticky\":0},{\"title\":\"下载条\",\"id\":\"download_banner\",\"isSticky\":1},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":1}]}"},{"_auto_id":"24","channel_name_en":"nba","modules":"{\"moduleList\":[{\"title\":\"精选视频\",\"id\":\"video_album\",\"videoType\":\"tag\",\"videoId\":\"aUWuwLpej2A=\"},{\"title\":\"热门赛程\",\"id\":\"sport_schedule\",\"matchType\":100000,\"isSticky\":0},{\"title\":\"下载条\",\"id\":\"download_banner\",\"isSticky\":1},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":1}]}"},{"_auto_id":"25","channel_name_en":"sports","modules":"{\"moduleList\":[{\"title\":\"精选视频\",\"id\":\"video_album\",\"videoType\":\"tag\",\"videoId\":\"aUWsy7NfgWs=\"},{\"title\":\"热门赛程\",\"id\":\"sport_schedule\",\"isSticky\":0},{\"title\":\"下载条\",\"id\":\"download_banner\",\"isSticky\":1},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":1}]}"},{"_auto_id":"26","channel_name_en":"college","modules":"{\"moduleList\":[{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"l_qq_com\",\"path\":\"Edu_GX_Button1\"},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"l_qq_com\",\"path\":\"Edu_GX_Rectangle1\"},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"w-l-qq-com\",\"path\":\"Edu_GX_Text1|Edu_GX_Text2\"},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"ad_block\",\"path\":\"edu_college_gg2.htm\",\"isSticky\":0},{\"title\":\"下载条\",\"id\":\"download_banner\",\"isSticky\":1},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":1}]}"},{"_auto_id":"27","channel_name_en":"gaokao","modules":"{\"moduleList\":[{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"ad_block\",\"path\":\"edu_gaokao_gg1.htm\",\"isSticky\":0},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"l_qq_com\",\"path\":\"Edu_GK_Rectangle_2019\"},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"l_qq_com\",\"path\":\"Edu_GK_Button_2019\"},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"l_qq_com\",\"path\":\"Edu_GK_Width1_left_Button_2019\"},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"w-l-qq-com\",\"path\":\"Edu_GK_Width1_UP_text1_2019|Edu_GK_Width1_down_text1_2019|Edu_GK_Width1_UP_text2_2019|Edu_GK_Width1_UP_text3_2019|Edu_GK_Width1_UP_text4_2019|Edu_GK_Width1_UP_text5_2019|Edu_GK_Width1_UP_text6_2019|Edu_GK_Width1_down_text2_2019|Edu_GK_Width1_down_text3_2019|Edu_GK_Width1_down_text4_2019|Edu_GK_Width1_down_text5_2019|Edu_GK_Width1_down_text6_2019|Edu_GK_Width1_right_text1_2019|Edu_GK_Width1_right_text2_2019|Edu_GK_Width1_right_text3_2019|Edu_GK_Width1_right_text4_2019\"},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":1},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"ad_block\",\"path\":\"edu_gaokao_gg2.htm\",\"isSticky\":1}]}"},{"_auto_id":"28","channel_name_en":"abroad","modules":"{\"moduleList\":[{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"l_qq_com\",\"path\":\"Edu_CG_Rectangle1_2019\"},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"w-l-qq-com\",\"path\":\"Edu_CG_Width1_down_text1_2019|Edu_CG_Width1_down_text2_2019|Edu_CG_Width1_down_text3_2019|Edu_CG_Width1_down_text4_2019|Edu_CG_Width1_down_text5_2019|Edu_CG_Width1_down_text6_2019|Edu_CG_Width1_down_text7_2019|Edu_CG_Width1_down_text8_2019\"},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"l_qq_com\",\"path\":\"Edu_CG_Button1_2019\"},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"l_qq_com\",\"path\":\"Edu_CG_Button2_2019\"},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":1},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"ad_block\",\"path\":\"edu_chuguo_gg2.htm\",\"isSticky\":1}]}"},{"_auto_id":"29","channel_name_en":"zxx","modules":"{\"moduleList\":[{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"l_qq_com\",\"path\":\"Edu_SZJY_Rectangle1\",\"isSticky\":0},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":1}]}"},{"_auto_id":"30","channel_name_en":"ky","modules":"{\"moduleList\":[{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"ad_block\",\"path\":\"edu_ky_gg1.htm\",\"isSticky\":0},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":1}]}"},{"_auto_id":"31","channel_name_en":"mba","modules":"{\"moduleList\":[{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"ad_block\",\"path\":\"edu_bschool_gg1.htm\",\"isSticky\":0},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"l_qq_com\",\"path\":\"Edu_MBA_Rectangle_2019\"},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"ad_block\",\"path\":\"edu_bcschool_gg2.htm\",\"isSticky\":0},{\"title\":\"下载条\",\"id\":\"download_banner\",\"isSticky\":1},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":1}]}"},{"_auto_id":"32","channel_name_en":"career","modules":"{\"moduleList\":[{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"ad_block\",\"path\":\"edu_career_gg1.htm\",\"isSticky\":0},{\"title\":\"广告推广位\",\"id\":\"ad_tuiguang\",\"category\":\"l_qq_com\",\"path\":\"Edu_ZYJY_Rectangle1\",\"isSticky\":0},{\"title\":\"下载条\",\"id\":\"download_banner\",\"isSticky\":1},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":1}]}"},{"_auto_id":"33","channel_name_en":"edu","modules":"{\"moduleList\":[{\"title\":\"精选视频\",\"id\":\"video_album\",\"videoType\":\"tag\",\"videoId\":\"aUWtwrxahGc=\",\"isSticky\":0},{\"title\":\"高考日历\",\"id\":\"xc_calendar\",\"calendarId\":81,\"startTime\":\"2024-05-22\",\"endTime\":\"2024-07-20\",\"isSticky\":0},{\"title\":\"下载条\",\"id\":\"download_banner\",\"isSticky\":1},{\"title\":\"热点榜\",\"id\":\"hot_rank_list\",\"isSticky\":1}]}"}],"channelNav":[{"_auto_id":"1","active_alien_img":"","alien_img":"","channel_id":"news_news_home","is_local":"0","link":"https://www.qq.com","name_cn":"首页","name_en":"home"},{"_auto_id":"2","active_alien_img":"","alien_img":"","channel_id":"news_news_top","is_local":"0","link":"","name_cn":"要闻","name_en":"news"},{"_auto_id":"3","active_alien_img":"","alien_img":"","channel_id":"news_news_bj","is_local":"1","link":"","name_cn":"北京","name_en":"bj"},{"_auto_id":"4","active_alien_img":"","alien_img":"","channel_id":"news_news_qa","is_local":"0","link":"","name_cn":"热问","name_en":"qa"},{"_auto_id":"5","active_alien_img":"","alien_img":"","channel_id":"news_news_finance","is_local":"0","link":"","name_cn":"财经","name_en":"finance"},{"_auto_id":"6","active_alien_img":"","alien_img":"","channel_id":"news_news_tech","is_local":"0","link":"","name_cn":"科技","name_en":"tech"},{"_auto_id":"7","active_alien_img":"","alien_img":"","channel_id":"news_news_football","is_local":"0","link":"","name_cn":"欧洲杯","name_en":"football"},{"_auto_id":"8","active_alien_img":"","alien_img":"","channel_id":"news_news_ent","is_local":"0","link":"","name_cn":"娱乐","name_en":"ent"},{"_auto_id":"9","active_alien_img":"","alien_img":"","channel_id":"news_news_sports","is_local":"0","link":"","name_cn":"体育","name_en":"sports"},{"_auto_id":"10","active_alien_img":"","alien_img":"","channel_id":"news_news_nba","is_local":"0","link":"","name_cn":"NBA","name_en":"nba"},{"_auto_id":"11","active_alien_img":"","alien_img":"","channel_id":"news_news_world","is_local":"0","link":"","name_cn":"国际","name_en":"world"},{"_auto_id":"12","active_alien_img":"","alien_img":"","channel_id":"news_news_mil","is_local":"0","link":"","name_cn":"军事","name_en":"milite"},{"_auto_id":"13","active_alien_img":"","alien_img":"","channel_id":"news_news_game","is_local":"0","link":"","name_cn":"游戏","name_en":"games"},{"_auto_id":"14","active_alien_img":"","alien_img":"","channel_id":"news_news_auto","is_local":"0","link":"","name_cn":"汽车","name_en":"auto"},{"_auto_id":"15","active_alien_img":"","alien_img":"","channel_id":"news_news_house","is_local":"0","link":"","name_cn":"房产","name_en":"house"},{"_auto_id":"16","active_alien_img":"","alien_img":"","channel_id":"news_news_antip","is_local":"0","link":"","name_cn":"健康","name_en":"health"},{"_auto_id":"17","active_alien_img":"","alien_img":"","channel_id":"news_news_edu","is_local":"0","link":"","name_cn":"教育","name_en":"edu"},{"_auto_id":"18","active_alien_img":"","alien_img":"","channel_id":"news_news_kepu","is_local":"0","link":"","name_cn":"科学","name_en":"kepu"},{"_auto_id":"19","active_alien_img":"","alien_img":"","channel_id":"cloud_gamer","is_local":"0","link":"https://gamer.qq.com/?ichannel=txxwpc0Ftxxwpc1","name_cn":"云游戏","name_en":"cloud_gamer"},{"_auto_id":"20","active_alien_img":"","alien_img":"","channel_id":"news_news_digi","is_local":"0","link":"","name_cn":"数码","name_en":"digi"},{"_auto_id":"21","active_alien_img":"","alien_img":"","channel_id":"news_news_esport","is_local":"0","link":"","name_cn":"电竞","name_en":"esport"},{"_auto_id":"22","active_alien_img":"","alien_img":"","channel_id":"news_news_history","is_local":"0","link":"","name_cn":"历史","name_en":"history"},{"_auto_id":"24","active_alien_img":"","alien_img":"","channel_id":"ymzx","is_local":"0","link":"https://gamer.qq.com/v2/cloudgame/game/96897?ichannel=txxwpc0Ftxxwpc1","name_cn":"元梦之星","name_en":"news_news_ymzx"},{"_auto_id":"25","active_alien_img":"","alien_img":"","channel_id":"news_news_nchupin","is_local":"0","link":"","name_cn":"眼界","name_en":"chupin"},{"_auto_id":"26","active_alien_img":"","alien_img":"","channel_id":"news_news_lic","is_local":"0","link":"","name_cn":"理财","name_en":"finance_licai"},{"_auto_id":"28","active_alien_img":"","alien_img":"","channel_id":"news_news_istock","is_local":"0","link":"","name_cn":"股票","name_en":"finance_stock"},{"_auto_id":"31","active_alien_img":"","alien_img":"","channel_id":"wwqy","is_local":"0","link":"https://val.qq.com/act/a20230801download/index.html?adtag=2473","name_cn":"无畏契约","name_en":"news_news_wwqy"},{"_auto_id":"32","active_alien_img":"","alien_img":"","channel_id":"edu_gaokao","is_local":"0","link":"https://new.qq.com/rain/a/UTR2024052000469400","name_cn":"高考","name_en":"gaokao"},{"_auto_id":"33","active_alien_img":"","alien_img":"","channel_id":"news_news_baby","is_local":"0","link":"","name_cn":"育儿","name_en":"baby"},{"_auto_id":"34","active_alien_img":"","alien_img":"","channel_id":"ren_min_shi_pin","is_local":"0","link":"https://news.qq.com/omn/author/8QMd3Hld74cbujbY?tab=om_video","name_cn":"人民视频","name_en":"ren_min_shi_pin"}],"channelNav2":[{"_auto_id":"1","channel1_name_en":"edu","channel_id":"news_news_college","link":"","name_cn":"高校","name_en":"college"},{"_auto_id":"3","channel1_name_en":"edu","channel_id":"news_news_gaokao","link":"","name_cn":"高考","name_en":"gaokao"},{"_auto_id":"7","channel1_name_en":"edu","channel_id":"news_news_abroad","link":"","name_cn":"出国","name_en":"abroad"},{"_auto_id":"8","channel1_name_en":"edu","channel_id":"news_news_zxx","link":"","name_cn":"素质教育","name_en":"zxx"},{"_auto_id":"9","channel1_name_en":"edu","channel_id":"news_news_ky","link":"","name_cn":"考研","name_en":"ky"},{"_auto_id":"10","channel1_name_en":"edu","channel_id":"news_news_mba","link":"","name_cn":"商学院","name_en":"mba"},{"_auto_id":"11","channel1_name_en":"edu","channel_id":"news_news_career","link":"","name_cn":"职业教育","name_en":"career"}],"channelSkin":[{"_auto_id":"1","banner_bg_img":"https://inews.gtimg.com/newsapp_bt/0/0918200759434_1210/0","banner_img":"https://mat1.gtimg.com/qqcdn/asian/dist/images/asian-esportbg.jpg","channel_key":"ent","end_time":"2024-05-16 12:15:03","is_banner":"0","link_url":"","search_text_color":"","skin_img":"","start_time":"2024-05-13 11:39:38"},{"_auto_id":"2","banner_bg_img":"","banner_img":"","channel_key":"ent","end_time":"2024-05-17 12:14:49","is_banner":"0","link_url":"https://new.qq.com/rain/a/UTR2023020600041500","search_text_color":"#6F335B","skin_img":"https://inews.gtimg.com/newsapp_bt/0/0511171414407_2863/0","start_time":"2024-05-11 17:38:36"},{"_auto_id":"3","banner_bg_img":"","banner_img":"","channel_key":"edu","end_time":"2025-06-30 16:28:44","is_banner":"0","link_url":"","search_text_color":"","skin_img":"https://inews.gtimg.com/newsapp_bt/0/0523183129178_7704/0","start_time":"2024-06-05 16:28:20"}],"channelAd":[{"_auto_id":"2","channel_name_en":"college","modules":"{\"moduleList\":[{\"title\":\"广告推广位\",\"id\":\"top\",\"category\":\"l_qq_com\",\"path\":\"Edu_GX_HP_Width1\"}]}"},{"_auto_id":"3","channel_name_en":"abroad","modules":"{\"moduleList\":[{\"title\":\"广告推广位\",\"id\":\"top\",\"category\":\"l_qq_com\",\"path\":\"Edu_CG_Width1_2019\"}]}"},{"_auto_id":"4","channel_name_en":"zxx","modules":"{\"moduleList\":[{\"title\":\"广告推广位\",\"id\":\"top\",\"category\":\"l_qq_com\",\"path\":\"Edu_SZJY_HP_Width1\"}]}"},{"_auto_id":"5","channel_name_en":"ky","modules":"{\"moduleList\":[{\"title\":\"广告推广位\",\"id\":\"top\",\"category\":\"l_qq_com\",\"path\":\"Edu_KY_HP_Width1\"}]}"},{"_auto_id":"6","channel_name_en":"mba","modules":"{\"moduleList\":[{\"title\":\"广告推广位\",\"id\":\"top\",\"category\":\"l_qq_com\",\"path\":\"Edu_MBA_Width1_2019\"}]}"},{"_auto_id":"7","channel_name_en":"career","modules":"{\"moduleList\":[{\"title\":\"广告推广位\",\"id\":\"top\",\"category\":\"l_qq_com\",\"path\":\"Edu_ZYJY_HP_Width1\"}]}"},{"_auto_id":"8","channel_name_en":"baby","modules":"{\"moduleList\":[{\"title\":\"广告推广位\",\"id\":\"top\",\"category\":\"l_qq_com\",\"path\":\"Baby_Width1_2019\"},{\"title\":\"广告推广位\",\"id\":\"bottom\",\"category\":\"l_qq_com\",\"path\":\"QQcom_all_Width1\"}]}"},{"_auto_id":"9","channel_name_en":"gaokao","modules":"{\"moduleList\":[{\"title\":\"广告推广位\",\"id\":\"top\",\"category\":\"l_qq_com\",\"path\":\"Edu_GK_Width1_2019\"}]}"},{"_auto_id":"12","channel_name_en":"cul","modules":"{\"moduleList\":[{\"title\":\"广告推广位\",\"id\":\"top\",\"category\":\"l_qq_com\",\"path\":\"QQcom_all_Width1-1\"},{\"title\":\"广告推广位\",\"id\":\"bottom\",\"category\":\"l_qq_com\",\"path\":\"QQcom_all_Width1-2\"}]}"},{"_auto_id":"13","channel_name_en":"chupin","modules":"{\"moduleList\":[{\"title\":\"广告推广位\",\"id\":\"top\",\"category\":\"l_qq_com\",\"path\":\"QQcom_all_Width1-1\"}]}"},{"_auto_id":"14","channel_name_en":"world","modules":"{\"moduleList\":[{\"title\":\"广告推广位\",\"id\":\"top\",\"category\":\"l_qq_com\",\"path\":\"QQcom_all_Width1-1\"},{\"title\":\"广告推广位\",\"id\":\"bottom\",\"category\":\"l_qq_com\",\"path\":\"QQcom_all_Width1-2\"}]}"},{"_auto_id":"15","channel_name_en":"football","modules":"{\"moduleList\":[{\"title\":\"广告推广位\",\"id\":\"top\",\"category\":\"l_qq_com\",\"path\":\"QQcom_all_Width1-1\"},{\"title\":\"广告推广位\",\"id\":\"bottom\",\"category\":\"l_qq_com\",\"path\":\"QQcom_all_Width1-2\"}]}"},{"_auto_id":"16","channel_name_en":"digi","modules":"{\"moduleList\":[{\"title\":\"广告推广位\",\"id\":\"top\",\"category\":\"l_qq_com\",\"path\":\"QQcom_all_Width1-1\"},{\"title\":\"广告推广位\",\"id\":\"bottom\",\"category\":\"l_qq_com\",\"path\":\"QQcom_all_Width1-2\"}]}"},{"_auto_id":"17","channel_name_en":"milite","modules":"{\"moduleList\":[{\"title\":\"广告推广位\",\"id\":\"top\",\"category\":\"l_qq_com\",\"path\":\"QQcom_all_Width1-1\"},{\"title\":\"广告推广位\",\"id\":\"bottom\",\"category\":\"l_qq_com\",\"path\":\"QQcom_all_Width1-2\"}]}"}],"channelSwiperAd":[{"_auto_id":"1","ad_img":"https://inews.gtimg.com/newsapp_bt/0/0604171047388_6738/0","ad_source":"启航智诚","ad_title":"第十一届腾讯商学院发展论坛暨专业学位教育年度峰会成功举办","channel_name_en":"zxx","end_time":"2024-12-31 16:28:44","position":"2","start_time":"2024-06-05 16:28:20","url":"https://new.qq.com/rain/a/UTR2023010300136600"},{"_auto_id":"2","ad_img":"https://inews.gtimg.com/newsapp_bt/0/0604170725506_6576/0","ad_source":"启航智诚","ad_title":"第十一届腾讯商学院发展论坛暨专业学位教育年度峰会成功举办","channel_name_en":"mba","end_time":"2024-12-31 16:28:44","position":"2","start_time":"2024-06-05 16:28:20","url":"https://new.qq.com/rain/a/UTR2023121700482300"},{"_auto_id":"3","ad_img":"https://inews.gtimg.com/newsapp_bt/0/0604170725506_6576/0","ad_source":"启航智诚","ad_title":"第十一届腾讯商学院发展论坛暨专业学位教育年度峰会成功举办","channel_name_en":"ky","end_time":"2024-12-31 16:28:44","position":"2","start_time":"2024-06-05 16:28:20","url":"https://new.qq.com/rain/a/UTR2023121700482300"},{"_auto_id":"4","ad_img":"https://inews.gtimg.com/newsapp_bt/0/06041718591_4137/0","ad_source":"启航智诚","ad_title":"腾讯新闻教育频道年度论坛|科技赋能 创新未来","channel_name_en":"career","end_time":"2024-12-31 16:28:44","position":"2","start_time":"2024-06-05 16:28:20","url":"https://huixiangchina.com/expage/2023hxzg"},{"_auto_id":"5","ad_img":"https://inews.gtimg.com/newsapp_bt/0/0612104903400_4390/0","ad_source":"中青美景","ad_title":"世界的三亚 三亚的大学-三亚学院欢迎您","channel_name_en":"college","end_time":"2024-12-31 23:38:59","position":"2","start_time":"2024-06-12 10:38:14","url":"https://zhaosheng.sanyau.edu.cn/"},{"_auto_id":"6","ad_img":"https://inews.gtimg.com/newsapp_bt/0/0613153348269_6899/0","ad_source":"好喆传媒","ad_title":"2024“翼展未来”家庭教育论坛暨国际学校联展","channel_name_en":"abroad","end_time":"2024-12-31 23:59:59","position":"3","start_time":"2024-06-13 15:36:28","url":"https://new.qq.com/rain/a/UTR2024060600718300"},{"_auto_id":"7","ad_img":"https://inews.gtimg.com/newsapp_bt/0/0614184659238_2292/0","ad_source":"中青美景","ad_title":"2024首都体育学院宣传片:《燃,青春!》震撼发布","channel_name_en":"gaokao","end_time":"2024-12-31 23:59:59","position":"3","start_time":"2024-06-14 18:47:20","url":"https://v.qq.com/x/page/u3552mwevx7.html"}],"channelGameRight":[{"_auto_id":"2","desc":"连续登录送游戏钻石,群雄共聚称霸沙城","icon":"https://inews.gtimg.com/newsapp_bt/0/0627161037914_3816/0","link":"https://s.iwan.qq.com/opengame/tenvideo/index.html?hidestatusbar=1&hidetitlebar=1&immersive=1&syswebview=1&landscape=1&gameid=49085&url=https%3A%2F%2Fgz-file.91ninthpalace.com%2Fwzzx%2Findex_tencent_iwan.html%20&ref_ele=90015","name":"王者之心2"},{"_auto_id":"3","desc":"上线送VIP!万人同屏横扫沙城","icon":"https://inews.gtimg.com/newsapp_bt/0/0627155752146_4584/0","link":"https://s.iwan.qq.com/opengame/tenvideo/index.html?hidestatusbar=1&hidetitlebar=1&immersive=1&landscape=1&syswebview=1&gameid=47203&url=https%3A%2F%2Fcqss2login.bigrnet.com%2Fiwan%2Fh5%2Fplay%2Floading&ref_ele=90015","name":"传奇盛世"},{"_auto_id":"4","desc":"超高爆率,经典玩法","icon":"https://inews.gtimg.com/newsapp_bt/0/0627160641137_9103/0","link":"https://s.iwan.qq.com/opengame/tenvideo/index.html?hidestatusbar=1&hidetitlebar=1&immersive=1&syswebview=1&gameid=43803&url=https%3A%2F%2Fsdk.mxzgame.com%2FGames%2Fportal%2F108337%2FTXVApp&ref_ele=90015","name":"新不良人"},{"_auto_id":"5","desc":"与范闲共赴“神仙局”","icon":"https://inews.gtimg.com/newsapp_bt/0/0627155220500_5777/0","link":"https://s.iwan.qq.com/opengame/tenvideo/index.html?hidestatusbar=1&hidetitlebar=1&immersive=1&syswebview=1&gameid=50192&url=https%3A%2F%2Fqyn.resources.3737.com%2Fx10_web%2Fh5_tx_sp%2Findex.html&ref_ele=90015","name":"庆余年小游戏"},{"_auto_id":"6","desc":"新服大放送,享赚你就来","icon":"https://inews.gtimg.com/newsapp_bt/0/0627154608860_7318/0","link":"https://s.iwan.qq.com/opengame/tenvideo/index.html?hidestatusbar=1&hidetitlebar=1&immersive=1&syswebview=1&landscape=1&gameid=43403&url=https%3A%2F%2Flogin-wxxyx2-bzsc.jikewan.com%2Fgame%2Fcqtxvideo.html&ref_ele=90015","name":"百战沙城"},{"_auto_id":"7","desc":"斗罗福利版,震撼上线","icon":"https://inews.gtimg.com/newsapp_bt/0/0627174713963_415/0","link":"https://s.iwan.qq.com/opengame/tenvideo/index.html?hidestatusbar=1&hidetitlebar=1&immersive=1&landscape=1&syswebview=1&gameid=43742&url=https%3A%2F%2Fxdldl-sq.sxmxwh.com%2Fsdk%2Fentry%2Fallu_micro_h5%2F8b75a856&ref_ele=90015","name":"斗罗大陆"},{"_auto_id":"8","desc":"原汁原味,正版授权","icon":"https://inews.gtimg.com/newsapp_bt/0/0627160844946_1794/0","link":"https://s.iwan.qq.com/opengame/tenvideo/index.html?hidetitlebar=1&immersive=1&syswebview=1&landscape=1&gameid=37275&url=https%3A%2F%2Fsdk.mxzgame.com%2FGames%2Fportal%2F100211%2FTXVApp&ref_ele=90015","name":"原始传奇"},{"_auto_id":"9","desc":"专注超爽打宝体验","icon":"https://inews.gtimg.com/newsapp_bt/0/0627154956673_3154/0","link":"https://s.iwan.qq.com/opengame/tenvideo/index.html?hidestatusbar=1&hidetitlebar=1&immersive=1&syswebview=1&gameid=41057&url=https%3A%2F%2Fh5apily.fire2333.com%2Fh5sdk%2Ftxshipin%2Findex%2F3200222%2F3200112&ref_ele=90015","name":"传奇至尊"},{"_auto_id":"10","desc":"赛季制实时PVP联机对战","icon":"https://inews.gtimg.com/newsapp_bt/0/0701165259701_7142/0","link":"https://s.iwan.qq.com/opengame/tenvideo/index.html?hidestatusbar=1&hidetitlebar=1&immersive=1&syswebview=1&gameid=49634&url=https%3A%2F%2Ffootball.shenshoucdn.com%2Ffootball_new%2Fh5%2Ftxsp%2Findex.html&ref_ele=90015","name":"球场风云"},{"_auto_id":"11","desc":"火爆新服,福利满满","icon":"https://inews.gtimg.com/newsapp_bt/0/0701171307639_4759/0","link":"https://s.iwan.qq.com/opengame/tenvideo/index.html?hidestatusbar=1&hidetitlebar=1&immersive=1&syswebview=1&gameid=50335&url=https%3A%2F%2Fh5-union-cdn.pptgame.cn%2Findex.html%3Ftx_package_id%3D10202%20&ref_ele=90015","name":"火源战纪"},{"_auto_id":"12","desc":"魔幻风格,超大场面","icon":"https://inews.gtimg.com/newsapp_bt/0/0701171500721_6895/0","link":"https://s.iwan.qq.com/opengame/tenvideo/index.html?hidestatusbar=1&hidetitlebar=1&immersive=1&syswebview=1&gameid=33112&url=https%3A%2F%2Fcsjs-tx.ebibi.com%2Fgame%2Fh5iwan-wwzs%2Fmain%2Findex.html&ref_ele=90015","name":"万王之神"},{"_auto_id":"13","desc":"登录领神秘巨星,打造巅峰阵容","icon":"https://inews.gtimg.com/newsapp_bt/0/0701170959368_8122/0","link":"https://s.iwan.qq.com/opengame/tenvideo/index.html?hidestatusbar=1&hidetitlebar=1&immersive=1&syswebview=1&gameid=40591&url=https%3A%2F%2Frh.diaigame.com%2Fh5plat%2Fplay%2Fpackage_code%2FP0012462&ref_ele=90015","name":"巅峰冠军足球"},{"_auto_id":"14","desc":"NBA正版页游戏,范特西经典重现","icon":"https://inews.gtimg.com/newsapp_bt/0/0701170609176_9908/0","link":"https://s.iwan.qq.com/opengame/tenvideo/index.html?hidestatusbar=1&hidetitlebar=1&immersive=1&syswebview=1&gameid=42445&url=https%3A%2F%2Fh5nba-txsports.ftxgame.com%2Fp%2Fmain%2Ftxvideo_index&ref_ele=90015","name":"NBA范特西"},{"_auto_id":"15","desc":"体验不一样的仙侠世界","icon":"https://inews.gtimg.com/newsapp_bt/0/0701170251358_3724/0","link":"https://s.iwan.qq.com/opengame/tenvideo/index.html?hidestatusbar=1&hidetitlebar=1&immersive=1&syswebview=1&gameid=39686&url=https%3A%2F%2Fsdk.gz.1253361160.clb.myqcloud.com%2FGames%2Fportal%2F108311%2FTXVApp&ref_ele=90015","name":"凡人神将传"}]}};
</script>
<script src="https://mat1.gtimg.com/www/js/emonitor/custom_ed041a23.js" charset="utf-8"></script>
<script>
  try {
    window.emonitorIns = emonitor.create({
      name: 'newsqq_channel',
      atta: {
        name: 'newsqq',
      },
      mode: '007',
    });
  } catch (err) {
    console.warn(err);
  }
</script>
<script src="https://mat1.gtimg.com/pingjs/ext2020/configF2017/5a978a31.js"></script>
<link href="https://mat1.gtimg.com/qqcdn/qqindex2021/channel/index-20247815235.css" rel="stylesheet">
</head>

<body>
  <div class="channel-root channel">
    <div id="top-nav"></div>
    <div id="content"></div>
  </div>

    <script type="text/javascript">
  var TIME_BEFORE_LOAD_CRYSTAL = Date.now();
</script>
<script type="text/javascript" src="https://mat1.gtimg.com/qqcdn/qqindex2021/advertisement/qqchannel/crystal.202406211446.min.js" charset="utf-8"></script>
<script type="text/javascript">
  if (typeof crystal === 'undefined' && Math.random() <= 1) {
    (function() {
      var TIME_AFTER_LOAD_CRYSTAL = Date.now();
      var img = new Image(1, 1);
      img.src = "//dp3.qq.com/qqcom/?adb=1&dm=new&err=1002&blockjs=" + (TIME_AFTER_LOAD_CRYSTAL - TIME_BEFORE_LOAD_CRYSTAL);
    })();
  }
</script>
    <iframe style="display: none;" src="https://i.news.qq.com/web_backend/getWebPacUid"></iframe>
<script src="https://mat1.gtimg.com/qqcdn/qqindex2021/static/20231212123233/react.production.min.js"></script>
<script src="https://mat1.gtimg.com/qqcdn/qqindex2021/static/20231212123233/react-dom.production.min.js"></script>
<script src="https://mat1.gtimg.com/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="https://staticfile.qq.com/datong/universalReportH5/v3.5.9/universal-report.min.js"></script>
<script defer async type="text/javascript" src="https://mat1.gtimg.com/qqcdn/qqindex2021/libs/barrier/aria.js?appid=9327b8b06379d9d1728bbfbe2025ef9c" charset="utf-8"></script>
<script src="https://staticfile.qq.com/qimei/qimeisdk-web/0.6.3/lite.js"></script>
<script src="https://t.captcha.qq.com/TCaptcha.js"></script>
<script>
  try {
    var qimeiWebLite = new QimeiWebLite({
      appKey: "f385d759261a9ef7"
    });
  } catch (error) {
    console.log(`QimeiWebLite实例化失败:${error}`);
  }
</script>
<script type="text/javascript" src="https://mat1.gtimg.com/qqcdn/qqindex2021/channel/index-20247815235.js"></script>
<iframe id="videoFrame" style="display: none;" src="https://video.qq.com/cookie/sync_qqnews.html"></iframe>
</body>

</html>

代码
文本

〉 解析页面

· HTML代码-网页解析器

· Json数据-json模块,转换成Json对象

· 二进制数据-以wb形式写入文件,再做进一步处理

此处使用bs4进行解析

代码
文本
[46]
!pip install beautifulsoup4 lxml

from bs4 import BeautifulSoup
soup =BeautifulSoup(r.text,'lxml')
for news in soup.find_all('div',class_='text'):
info = news.find('a')
if len(info)>0:
title = info.get_text()
link = str(info.get('href'))
print('标题:'+ title)
print('链接:'+link +'\n')
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: beautifulsoup4 in /opt/conda/lib/python3.8/site-packages (4.11.1)
Requirement already satisfied: lxml in /opt/conda/lib/python3.8/site-packages (4.9.2)
Requirement already satisfied: soupsieve>1.2 in /opt/conda/lib/python3.8/site-packages (from beautifulsoup4) (2.3.2.post1)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
代码
文本

56-数据可视化:绘制数据图表

〉 numpy矩阵处理库

〉 matplotlib绘图库

〉 基本思路

〉 简单函数图形

〉 定制线形/标签图例

〉 散点图和直方图

代码
文本

numpy库

〉 numpy是Python用于处理大型矩阵的一个速度极快的数学库

可以做向量和矩阵的运算,包括各种创建矩阵的方法,以及一般的矩阵运算、求逆、求转置

〉 它的很多底层的函数都是用C写的,可以得到在普通Python中无法达到的运行速度

代码
文本

〉 numpy方法

· 矩阵计算

创建矩阵 a = np.matrix([ ])

矩阵求逆 a.I

矩阵转置 a.T

矩阵乘法 a*b或np.dot(a,b)

· 对象属性

np.shape 数组形状,矩阵则为n行m列

np.size 对象元素的个数

np.dtype 指定当前numpy对象的整体数据

代码
文本
[30]
import numpy as np
a= np.matrix([[1,2],[3,4]])
a.I

a.T

a.I * a

b= np.matrix([[7,6],[5,4]])
a*b
a.dtype

a.shape

a.size
4
代码
文本

matplotlib绘图库

〉 matplotlib是Python的一个绘图库。它包含了大量的工具,可以使用这些工具创 建各种图形

简单的散点图、折线图,甚至三维图形、动画等

代码
文本

〉 matplotlib功能异常强大

http://matplotlib.org/gallery.html

〉 Python科学计算社区经常使用它完成数据可视化的工作

代码
文本

绘制函数图像基本思路

〉 基本思路

通过将图像上一些点的坐标连接起来,即可绘制函数的近似图像,当点越多时,所绘图像越接近函数图像

〉 numpy库的linspace(￿)函数生成数组

numpy.linspace(,,)

生成一个存放等差数列的数组,数组元素为浮点型,包含三个参数,分别是:数列起始值、终止值(默认包含自身)、数列元素个数

〉 matplotlib库的plot(￿)函数用来画图

可以设定图形颜色、线条线型、以及做标注等

代码
文本

简单图形

代码
文本
[32]
import matplotlib.pyplot as plt
import numpy as np

#简单的绘图
x= np.linspace(0,2*np.pi,50)

# 如果没有第一个参数 x,图形的 x坐标默认为数组的索引
plt.plot(x,np.sin(x))

plt.show()# 显示图形
代码
文本

多个简单图形

代码
文本
[36]
import matplotlib.pyplot as plt
import numpy as np

x= np.linspace(0,2*np.pi,50)
plt.plot(x,np.sin(x),x,np.sin(2 *x))
plt.show()
代码
文本

定制线型

〉 plot()函数的绘制样式参数表示

· 颜色

alt

· 线型与点型

alt

代码
文本
[39]
import matplotlib.pyplot as plt
import numpy as np

#自定义曲线的外观
x=np.linspace(0,2*np.pi,50)
plt.plot(x,np.sin(x),'r-o',x,np.cos(x),'g--')
plt.show()
代码
文本

标签图例

〉 坐标轴标签

plt.xlabel()、plt.ylabel()

〉 图形标题

plt.title()

代码
文本

散点图

〉 函数scatter(x,y)

(x, y)是点的坐标

代码
文本
[42]
import matplotlib.pyplot as plt
import numpy as np

#简单的散点图
x = np.linspace(0,2*np.pi,50)
y = np.sin(x)
plt.scatter(x,y)
plt.show()
代码
文本

直方图

〉 函数hist(x,n)

x是横坐标,n是条状图的数量

代码
文本
[43]
import matplotlib.pyplot as plt
import numpy as np

# 直方图
x= np.random.randn(1000)
plt.hist(x,50)
plt.show()
代码
文本

57-上机练习:高级扩展模块应用

〉 信息隐藏工具

〉 微博系统

〉 蒙特卡罗方法求圆周率

代码
文本

上机练习1:信息隐藏工具

〉 轻微改变图片中像素的RGB值,肉眼无法察觉

〉 将8bit￿R/G/B中的最低1bit,用于隐藏一个数据文件(如文本)

每3个像素可以隐藏1个字节

〉 注意使用不失真图像格式BMP/PNG格式

〉 要求:

1)提供图片和数据文件,生成隐藏信息的图片

2)从隐藏信息的图片中提取数据文件

代码
文本
[ ]
#上机练习1:

代码
文本

上机练习2:微博系统

〉 开发一个单用户的微博系统

可以浏览、发帖、删帖、回复

利用Flask编程/shelve持久存储

代码
文本
[ ]
#上机练习2:

代码
文本

上机练习3:蒙特卡罗方法求圆周率

〉 蒙特卡罗方法原理

通过大量随机样本,去了解一个系统,进而得到所要计算的值

〉 用蒙特卡罗方法计算圆周率π

正方形内部有一个相切的圆

在这个正方形内部,随机产生10000个点,计算它们与中心点的距离,从而判断是否落在圆的内部

如果这些点均匀分布,那么圆内的点应该占到所有点的 π/4

〉 用matplotlib可视化

代码
文本
[ ]
#上机练习3:

代码
文本
python
python
已赞1
推荐阅读
公开
走进科学计算_07_图像处理与分析
中文python科学计算
中文python科学计算
ck
发布于 2023-08-20
4 转存文件1 评论
公开
陈君花-第3天-2403-计算材料学原理
2403-计算材料学原理
2403-计算材料学原理
Chen0025
发布于 2024-03-10