欢迎来到君如的灵感空间
# 导入所需库import requestsfrom bs4 import BeautifulSoup# 定义爬取海贼王漫画的函数def crawl_one_piece(): # 设置请求头 headers = 'User-Agent': 'Mozilla5.0 (Windows NT 10.0; Win64; x64) AppleWebKit537.36 (KHTML, like Gecko) Chrome58.0.3029.110 Safari537.3' # 发送请求,获取网页内容 response = requests.get('onepiece.com', headers=headers) html_content = response.text # 使用BeautifulSoup解析网页内容 soup = BeautifulSoup(html_content, 'html.parser') # 提取漫画章节标题 chapter_titles = soup.find_all('div', class_='chap