您当前的位置: 首页 >  彭世瑜 Python

Python编程:BeautifulSoup和Selector解析网页示例

彭世瑜 发布时间:2019-03-04 13:48:48 ,浏览量:3

殊途同归

# -*- 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)
# 百度一下,你就知道

关注
打赏
1688896170
查看更多评论

彭世瑜

暂无认证

  • 3浏览

    0关注

    2727博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0536s