一、整理笔记 1.文本处理 <!DOCTYPE html> <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> </li> <li>米</li> <li>油</li> </ul> </body> </html> 2.分区元素 <!DOCTYPE html> <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.图片和超链接 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>图片和超链接</title> </head> <body> <!--alt 当图片显示时,alt不显示--> <img src='D:\workspace\python\day10\u=315216092,3999902507&fm=26&gp=0.jpg',alt='肖战',width='100',heighth='50'> <hr> <!--超链接--> <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> </tr> <tr> <td>ddddd</td> <td>fffff</td> </tr> <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="">美食 <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' 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)
|