beautifulsoup CSS选择器解析方法
from turtle import title from bs4 import BeautifulSoup import requests def main(): r = requests.get("https://wwww.baidu.com") r.encoding="utf-8" html = r.text soup = BeautifulSoup(html, features="lxml") title = soup.select("html head title")[0].get_text() print(title) if __name__ == "__main__": main()
结果: