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()

结果:

 

posted @ 2022-04-07 15:25  波罗斯の程序日记  阅读(52)  评论(0编辑  收藏  举报