爬取西游记章节名

目录

  • 1.代码:
  • 2.效果:
  • 小结:

1.代码:

from bs4 import BeautifulSoup
import requests

url = 'https://www.shicimingju.com/book/xiyouji.html'
header = {'user-agent': 'Mozilla/5.0'}
response = requests.get(url=url, headers=header)
response.encoding = response.apparent_encoding

page_text = response.text
soup = BeautifulSoup(page_text, 'html.parser')

li_list = soup.select('.book-mulu>ul>li')
for li in li_list:
    title = li.a.text
    print(title)

2.效果:

爬取西游记章节名_第1张图片
爬取西游记章节名_第2张图片

小结:

关注我给大家分享更多有趣的知识,以下是个人公众号,提供 ||代码兼职|| ||代码问题求解||
由于本号流量还不足以发表推广,搜我的公众号即可:
在这里插入图片描述

你可能感兴趣的:(#,爬虫,爬虫,网络爬虫,数据库,数据分析,大数据,数据挖掘,big,data)