[問題] 請問爬蟲 bs4的擷取方法?

看板Python作者 (楚留香雞排)時間5年前 (2020/06/29 21:38), 編輯推噓3(3014)
留言17則, 4人參與, 5年前最新討論串1/1
如題目 用原始碼會是一片這樣 logged_user = false; var static_id_cdn = 2; var html5player = new HTML5Player('html5video', '25522515'); if (html5player) { html5player.setVideoTitle('); html5player.setSponsors([{}]); html5player.setVideoUrlLoW........... 其實還滿整齊的 我所要的網址都擺在了html5player.setVideoUrlLow裡面 使用bs4是好選擇嗎?該如何操作? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.220.255.143 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1593437935.A.94F.html

06/30 00:03, 5年前 , 1F
bs4不能解析js,如果re能抓出來就re吧,下策就seleni
06/30 00:03, 1F

06/30 00:03, 5年前 , 2F
um
06/30 00:03, 2F

06/30 01:36, 5年前 , 3F
嗯。通常是去看js完後它把資料丟哪去了。然後去抓那個結
06/30 01:36, 3F

06/30 01:36, 5年前 , 4F
06/30 01:36, 4F

06/30 01:37, 5年前 , 5F
建議可以po個網址來看看省時間
06/30 01:37, 5F

07/01 08:25, 5年前 , 6F
請問碰到html會先用xpath還是bs4?兩個不太會選
07/01 08:25, 6F

07/01 13:26, 5年前 , 7F
bs4有css也有xpath.如果用parsel(scrapy)只有xpath.所以
07/01 13:26, 7F

07/01 13:29, 5年前 , 8F
bs4有個參數有html.parser/lxml/html5lib但只是速度不同
07/01 13:29, 8F

07/01 13:32, 5年前 , 9F
或你也可以用html.parser模組的HTMLParser類自己刻一個
07/01 13:32, 9F

07/01 13:35, 5年前 , 10F
或用html2text模組不parse自己去找內容
07/01 13:35, 10F

07/01 13:40, 5年前 , 11F
所以bs4和xpath不是對比的選擇.而是xpath是bs4的選項之1
07/01 13:40, 11F

07/01 13:42, 5年前 , 12F
bs4不能解析js是因為js需要瀏覽器才能跑(除非是node.js)
07/01 13:42, 12F

07/01 15:01, 5年前 , 13F
我都爬出來找,xpath直接放棄...XD
07/01 15:01, 13F

07/01 15:20, 5年前 , 14F
感謝大大解答
07/01 15:20, 14F

07/06 23:24, 5年前 , 15F
^^
07/06 23:24, 15F

07/06 23:25, 5年前 , 16F
如果還是說明不清楚可以說
07/06 23:25, 16F

07/06 23:29, 5年前 , 17F
通常是css和xpath混用吧看哪一個可以達到目標
07/06 23:29, 17F
文章代碼(AID): #1U-UxlbF (Python)
文章代碼(AID): #1U-UxlbF (Python)