https://www.yicai.com/news/101547728.html
时间: 2023-06-21 18:04:30 浏览: 61
这是一篇关于OpenAI公司开发的GPT-3语言模型的文章。GPT-3是目前最先进的自然语言处理模型之一,能够生成高质量的自然语言文本,并且还可以执行简单的任务,如翻译、问答和摘要等。该模型使用了数百亿个参数,并且通过对大量文本数据的学习来提高其性能。GPT-3的应用范围非常广泛,包括人工智能助手、智能客服、自动写作等。
相关问题
请使用Python新建一个脚本,抓取第--财经网前五页的新闻标题及新闻链接,并将源代码和运行结果复制到Word
好的,以下是 Python 代码,请注意修改 Word 文件路径和第--财经网的页数:
```python
import requests
from bs4 import BeautifulSoup
import win32com.client
# 设置请求头,防止请求被拦截
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
# 定义抓取函数
def get_news(page):
url = 'https://www.yicai.com/api/ajax/getjuhelist?page={}&pagesize=30&nodeids=582'.format(page)
res = requests.get(url, headers=headers)
soup = BeautifulSoup(res.text, 'html.parser')
news_list = soup.find_all('a', class_='news-item')
for news in news_list:
title = news.find('div', class_='news-title').text.strip()
link = news['href']
print(title, link)
# 将结果复制到剪贴板
w = win32com.client.Dispatch('Word.Application')
w.Visible = 1
doc = w.Documents.Open("Word 文件路径")
doc.Bookmarks("result").Range.Text = "{} {}\n".format(title, link)
doc.Save()
doc.Close()
# 抓取前五页的新闻
for page in range(1, 6):
get_news(page)
```
在运行脚本前,需要先安装 requests 和 beautifulsoup4 模块,可以使用以下命令安装:
```
pip install requests
pip install beautifulsoup4
```
运行结果将会输出到控制台,并将结果复制到 Word 文件中的“result”书签处。请注意将“Word 文件路径”修改为你的 Word 文件所在路径。