殊途同归
# -*- coding: utf-8 -*- from bs4 import BeautifulSoup import requests from parsel import Selector # 下载网页 url = "https://www.baidu.com/" response = requests.get(url) response.encoding = response.apparent_encoding # BeautifulSoup解析网页 soup = BeautifulSoup(response.text, "html.parser") title = soup.find("title") print(title.text) # 百度一下,你就知道 # Selector解析网页 sel = Selector(text=response.text) title = sel.css("title::text").extract_first() print(title) # 百度一下,你就知道