Re: [問題] 請教bs4 一些問題

看板Python作者 (貓橘毛發呆雕像)時間8年前 (2017/03/24 14:04), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《mater2004 (mater)》之銘言: : http://i.imgur.com/IbIlco2.png
: 1.請問單獨打links[0] 可以正確顯示第一個 : 為什麼打兩個links[0,1]不行顯示兩個 list 切分(slice) 用冒號(:) 不是用逗號(,) , 正確用法是 links[0:1] 或省略 0 => links[:1]。 : 2.下面的 TypeError: list indices must be integers or slices, not tuple : 它不是原本就是lists嗎 怎麼變成tuple 「list 索引必須是數字或 slice 型態,不該是 tuple 型態。」 使用逗號(,)分隔的項目會自動識別為 tuple 型態。 : ---------------------------------- : http://i.imgur.com/lkRhUSK.png
: 3. : #links[0].get('href') #'ht//example.com/lacie' : #links[0].contents # ['Lacie'] : 請問這種取出內容物的方法是怎麼知道的 : 書上沒寫links[0].get('href')的話 我不會知道它可以這樣用 1. repl 下 help() 該物件 1.1 repl 下 dir() 該物件 2. 查該 library 的 API 文件 : ----------------------------- : 4.我發現有些網站 我放入Beautifulsoup後 : 例: import requests : from bs4 import BeautifulSoup : res = requests.get('http://xxx.xxx').text : soup = BeautifulSoup(res,"html.parser") : print(soup) : 印出來的東西,有些tag會顯示不出來,好像是包含在<div>內的 tag都不會顯示 沒網址沒真相,通靈一下可能的情況為: 1. 網頁動態 render, request 回來的東西不全 2. 被擋爬蟲 3. ?????? (黑人問號) -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 192.19.253.250 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1490335441.A.43B.html

03/24 21:48, , 1F
幫你通靈再加一個 paser 本身有缺陷.
03/24 21:48, 1F
文章代碼(AID): #1OrBRHGx (Python)
文章代碼(AID): #1OrBRHGx (Python)