当年高考作文题目程序

import requests
from bs4 import BeautifulSoup

url = 'http://www.gaokao.com/e/2021/2021-06-08/112583.html'  # 当年高考作文题目所在页面的链接
response = requests.get(url)
response.encoding = 'utf-8'  # 指定编码方式,避免中文乱码
soup = BeautifulSoup(response.text, 'html.parser')  # 解析网页内容

title = soup.find('div', class_='title').h1.text.strip()  # 获取作文题目
content = soup.find('div', class_='content').text.strip()  # 获取作文题目描述
print(f'当前年份高考作文题目:{
      
      title}')
print(f'作文题目描述:{
      
      content}')

请注意修改url中的链接,确保代码可以准确地获取您所需要的作文题目。另外,由于每年高考作文题目所在页面的结构可能会有所不同,请根据实际情况对代码进行适当的调整。

猜你喜欢

转载自blog.csdn.net/weixin_51378457/article/details/129478843