python爬虫——html页面


三、根据所给的html页面,保持为字符串,完成如下要求:

(1)打印head标签内容和你学号的后两位

(2)获取body标签的内容

(3)获取id的first的标签对象

(4)获取并打印html页面中的中文字符


from
bs4 import BeautifulSoup r = ''' <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com) 30号的作业</title> </head> <body> <h1>我的第一个标题</h1> <p id="first">我的第一个段落。</p> </body> <table border="1"> <tr> <td>row 1, cell 1</td> <td>row 1, cell 2</td> </tr> </table> </html> ''' demo = BeautifulSoup(r,"html.parser") print(demo.title) print(demo.body) print(demo.p) print(demo.string)

posted @ 2020-12-13 13:24  小松可可奈  阅读(437)  评论(0)    收藏  举报