参考笔记
下面给出一个巨佬学习风变pyhton基础语法和爬虫精进的笔记(链接)
风变编程笔记(一)-Python基础语法
风变编程笔记(二)-Python爬虫精进
技术总结
request + BeautifulSoup
selenium + BeautifulSoup
练习0-1:文章下载
import requests
res=requests.get('https://localprod.pandateacher.com/python-manuscript/crawler-html/exercise/HTTP%E5%93%8D%E5%BA%94%E7%8A%B6%E6%80%81%E7%A0%81.md')
files=res.text
print(files)
myfiles=open('myfiles.txt','w+')
myfiles.write(files)
myfiles.close()
练习0-2:图像下载
import requests
res=requests.get('https://res.pandateacher.com/2019-01-12-15-29-33.png')
pic = res.content
photo = open('ppt1.jpg','wb')
#新建了一个文件ppt.jpg,这里的文件没加路径,它会被保存在程序运行的当前目录下。
#图片内容需要以二进制wb读写。你在学习open()函数时接触过它。
photo.write(pic)
#获取pic的二进制内容
photo.close()
练习0-3:音频下载
import requests
rec=requests.get('https://static.pandateacher.com/Over%20The%20Rainbow.mp3')
req=rec.content
mymusic=open('mymusic1.mp3','wb')
mymusic.write(req)
mymusic.close()
练习1-1:我的书苑我做主
必做:
修改网页标题
增加至少一本书的描述
修改网页底部
选做:
修改已有书籍的描述
增加多本书的描述
自由地在HTML文档上修改任意内容
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>这个书苑不太冷5.0</title>
<style>
a {
text-decoration: none;
}
body {
margin: 0;
width:100%;
height: 100%;
}
#header {
background-color:#0c1f27;
color:#20b2aa;
text-align:center;
padding:15px;
}
#nav {
line-height:60px;
background-color:#e0f2f0;
width:80px;
padding:30px;
position: absolute;
left: 0;
top:0;
bottom: 0;
}
#footer {
background-color:#0c1f27;
color:#20b2aa;
clear:both;
text-align:center;
padding:35px;
}
#main {
margin-left: 140px;
padding-left: 150px;
padding-right: 220px;
overflow: scroll;
}
#article {
display: flex;
position: relative;
}
.catlog{
font-size:20px;
color:black;
font-family: sans-serif;
}
.title {
color:#20b2aa;
font-size:20px;
}
.img {
width: 185px;
height: 266px;
}
</style>
</head>
<body>
<div id="header">
<h1 style="font-size:50px;">这个书苑不太冷</h1>
</div>
<div id="article">
<div id="nav">
<a href="#type1" class="catlog">科幻小说</a><br>
<a href="#type2" class="catlog">人文读物</a><br>
<a href="#type3" class="catlog">技术参考</a><br>
</div>
<div id="main">
<div class="books">
<h2><a name="type1"</