三、将一个HTML页面保持为字符串  

from bs4 import BeautifulSoup
import re
soup=BeautifulSoup("<head><title>菜鸟教程(runoob.com)</title></head><body><h1>我的第一个标题</h1><p id="frist">我的第一个段落。</p></body><tr><td>row 1,cell 1</td><td>row 1,cell 2</td></tr><tr><td>row 2,cell 1</td><td>row 2,cell 2</td></tr></body></table>","html.parser")
print(soup.head,"42")   #打印head的内容和我的学号后两位
print(soup.body)      #打印body的内容
print(soup.find_all(id="china"))  #打印id为china的文本
r=soup.text
pattern = re.findall(u'[\u1100-\uFFFDh]+?',r)
print(pattern)

  

posted @ 2020-05-13 14:50  Leeingli  阅读(532)  评论(0编辑  收藏  举报