import requests
from bs4 import BeautifulSoup
import re
r = requests.get("http://python123.io/ws/demo.html")
demo = r.text
soup = BeautifulSoup(demo,"html.parser")print(soup.find_all('a'))#標籤名稱nameprint("--------------")print(soup.find_all('a','b'))print("--------------")print(soup.find_all('p','course'))#標籤屬性值attrsprint("--------------")print(soup.find_all('a', recursive=False))#子孫檢索recursiveprint("--------------")print(soup.find_all(string ="Basic Python"))#字符串stringprint("--------------")print(soup.find_all(string= re.compile("python")))#正則表達式
[<a class="py1" href="http://www.icourse163.org/course/BIT-268001"id="link1">Basic Python</a>,<a class="py2" href="http://www.icourse163.org/course/BIT-1001870001"id="link2">Advanced Python</a>]--------------[]--------------[<p class="course">Python is a wonderful general-purpose programming language. You can learn Python from novice to professional by tracking the following courses:<a class="py1" href="http://www.icourse163.org/course/BIT-268001"id="link1">Basic Python</a>and<a class="py2" href="http://www.icourse163.org/course/BIT-1001870001"id="link2">Advanced Python</a>.</p>]--------------[]--------------['Basic Python']--------------['This is a python demo page','The demo python introduces several python courses.']