畑乃おいも / Hatano Oimo
79 字
1 分鐘
使用Visual Studio Code 寫爬蟲網站網頁結果無法完整顯示
問題
使用 VSC 寫爬蟲會遇到一個問題是 Print 出來的內容無法完整印出來,寫入一個 HTML 檔案就可以方便看結果。
程式碼
import requestsfrom bs4 import BeautifulSoupurl = "https://google.com"res = requests.get(url)soup = BeautifulSoup(res.text, 'html.parser')law = soup.select('.law-content div')
#寫入my.htmlwith open('my.html', 'w', encoding='UTF-8') as f: f.write(str(law))使用Visual Studio Code 寫爬蟲網站網頁結果無法完整顯示
https://aishuafei.com/posts/使用visual-studio-code-寫爬蟲網站網頁結果無法完整顯示/