作者zerof (猫橘毛发呆雕像)
看板Python
标题Re: [问题] 请教bs4 一些问题
时间Fri Mar 24 14:03:57 2017
※ 引述《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://webptt.com/cn.aspx?n=bbs/Python/M.1490335441.A.43B.html
1F:→ s860134: 帮你通灵再加一个 paser 本身有缺陷. 03/24 21:48