79 字
1 分鐘
使用Visual Studio Code 寫爬蟲網站網頁結果無法完整顯示

問題#

使用 VSC 寫爬蟲會遇到一個問題是 Print 出來的內容無法完整印出來,寫入一個 HTML 檔案就可以方便看結果。

程式碼#

import requests
from bs4 import BeautifulSoup
url = "https://google.com"
res = requests.get(url)
soup = BeautifulSoup(res.text, 'html.parser')
law = soup.select('.law-content div')
#寫入my.html
with open('my.html', 'w', encoding='UTF-8') as f:
f.write(str(law))
使用Visual Studio Code 寫爬蟲網站網頁結果無法完整顯示
https://aishuafei.com/posts/使用visual-studio-code-寫爬蟲網站網頁結果無法完整顯示/
作者
愛耍廢
發佈於
2020-01-08
許可協議
CC BY-NC-SA 4.0