BeautifulSoup入门
import requests
from bs4 import BeautifulSoup
url = 'http://python123.io/ws/demo.html'
r = requests.get(url,)
demo = r.text
soup = BeautifulSoup(demo, 'html.parser') #'html.parser'用于解析html的解释器
#soup = BeautifulSoup(open("D://demo.html"), 'html.parser')
# print(soup.prettify()) #输出树形结构
title = soup.title
tag = soup.a #通过soup.<tag>的方式获取某个标签
soup.p.string
tag.attrs#返回一个字典
print(title,"\n",tag)
print(tag.attrs)
print(tag.attrs["href"])
print(soup.p.string)
print(tag.name) #a
print(tag.parent.name)#p
print(tag.parent.parent.name)#body