一、整理笔记 1.文本处理 <html lang="en"> <head> <meta charset="UTF-8"> <title>文本处理</title> </head> <body> <h1>测试开发40</h1> <h3>哈哈哈哈</h3> <!--段落--> <p>凉风习习,舟如在冰上行。到过了高丽界,海水竟似湖光。蓝极绿极,凝成一片.斜阳的金光,长蛇般自天边直接到阑旁人立处.上自穹苍,下至船前的水,自浅红至于深翠,幻成几十色,一层层,一片片的漾开了来.……小朋友,恨我不能画,文字竟是世界上最无用的东西,写不出这空灵的妙景。</p> <img src="D:\workspace\python\day10\微信图片_20210127181634.jpg"> <!--列表--> <ol><!--有序列表--> <li> 美国 <!--列表嵌套--> <ol> <li>加州</li> <li>美洲</li> </ol> </li> <li>中国</li> </ol> <ul><!--无序列表--> <li> 面 <ol> <ul>担担面</ul> <ul>biangbiang面</ul> <ul>刀削面</ul> </ol> </ul> </body> </html> 2.分区元素 <html lang="en"> <head> <meta charset="UTF-8"> <title>分区元素</title> <style> div{ border:1px solid #00ff80; } p{ color :#00ff80 } span{ color:black } </style> </head> <body> <!--块元素:独占一行--> <div> <p>吃饭饭</p> </div> <div> 睡觉觉 </div> <div> <!--行内元素:行内不独占一行--> <span>hahahaha</span> <p>wwwwwwww<span>baibaibai</span>wwwwww</p> </div> </body> </html> 3.图片和超链接 <html lang="en"> <head> <meta charset="UTF-8"> <title>图片和超链接</title> </head> <body> <img src='D:\workspace\python\day10\u=315216092,3999902507&fm=26&gp=0.jpg',alt='肖战',width='100',heighth='50'> <!--超链接--> <a href="https://www.baidu.com/?tn=62095104_23_oem_dg">百度</a> <a href="https://www.baidu.com/?tn=62095104_23_oem_dg"> <img src="D:\workspace\python\day10\u=315216092,3999902507&fm=26&gp=0.jpg",alt='肖战',width='200'> </a> </body> </html> 4.表格 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>表格</title> </head> <body> <!--cellspacing='0',cellpadding='0' 边距设置为0--> <table border="1px" cellspacing='0',cellpadding='0'> <!--一行--> <tr> <td>aaaaa</td> <td>bbbbb</td> <td>ccccc</td> </tr> <!--行扩展--> <td colspan='3'> gggg</td> </tr> </table> </body> </html> 5.<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>表单</title> </head> <body> <form action="https://www.baidu.com"> <!--文本输入框--> 账号:<input type='text' name='account'> <br><br> 密码:<input type='password' name='password'><br> <input type='submit' value='注册'><br> <hr> <!--radio :单选--> 性别:<input type="radio" name="gender" id="">男 <input type="radio" name="gender" id="">女dat <br><br> <!--checkbox :多选--> 爱好:<input type="checkbox" name="hobby" id="">游戏 <input type="checkbox" name="hobby" id="">美食 <br><br> 城市:<!--下拉框--> <select name="city" id=""> <option value='0'>--请选择--</option> <option value='1'>西安</option> <option value='2'>渭南</option> </select> <input type="date" name="" id=""> </form> </body> </html> 6.import requests from lxml import etree headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'} r = requests.get('https://www.baidu.com',headers=headers) #设置编码集 r.encoding = 'utf-8' #定位元素 #将字符串格式的网页转变成etree格式 selector = etree.HTML(r.text) #获取图片地址 href = selector.xpath('//*[@id="s_lg_img"]/@src')[0] # print(href) #下载图片 response = requests.get('https:'+href) print(response.content) with open('D:\workspace\python\day10\suo.png','wb')as file: file.write(response.content)
|