看板 Python 關於我們 聯絡資訊
import requests res = requests.get('http://money.cnn.com/2017/03/10/news/economy/february-j obs-report/index.html') from bs4 import BeautifulSoup soup = BeautifulSoup(res) print(soup.text) --------------------- 我在jupyter執行會出現 http://i.imgur.com/UIWbbPP.jpg --------------------- 我是照著實例做,網址改掉而已。 我只知道應該要印出沒有tag的 內容 不懂問題在哪 我試著改這行 soup= BeautifulSoup((res), "html.parser") 改完後出現 http://i.imgur.com/Fptoc3L.jpg 但我看不懂 ------- 另外html.parser是什麼? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 211.72.106.139 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1489182057.A.4AB.html
woogee: soup = BeautifulSoup(res) 改 03/11 06:32
woogee: soup = BeautifulSoup(res.text) 03/11 06:32
woogee: requests是回傳status code,要取得內容要用.text 03/11 06:33
woogee: html.parser是新版BeautifulSoup要告訴他是用哪一種parser 03/11 06:34
woogee: 抱歉,requests不是回傳status code,我說錯了 03/11 06:34
woogee: 他是回傳Response,要取得內容要用.text 03/11 06:35
mater2004: 請問requests 回傳 response要如何得知 03/11 16:23
mater2004: response是瀏覽器開發人員裡面的response嗎 03/11 16:24
zerof: response 是指 requests 的 response object.. 03/11 22:23
woogee: response就是requests回傳的東西叫做response 03/12 22:54