從網路可以取得許多資料,接下來若能把這些資料轉成Word檔,那就更完美了,記得要先安裝pip3 install python-docx。
import requests
from bs4 import BeautifulSoup
from docx import Document
from docx.shared import Inches
url = "http://www.nkut.edu.tw"
re = requests.get(url)
re.encoding='utf8'
soup = BeautifulSoup(re.text, 'html.parser')
html_inforamtion = soup.find('p')
print(html_inforamtion)
document = Document()
document.add_heading('南開科技大學', 0)
p = document.add_paragraph(html_inforamtion)
document.save('nkut.docx')
以下是print(html_inforamtion)的結果
Word的存檔路徑
查看輸出的Word檔
沒有留言:
張貼留言