作者mater2004 (mater)
看板Python
标题[问题] bs4 一些问题
时间Fri Mar 24 13:17:47 2017
http://i.imgur.com/IbIlco2.png
1.请问单独打links[0] 可以正确显示第一个
为什麽打两个links[0,1]不行显示两个
2.下面的 TypeError: list indices must be integers or slices, not tuple
它不是原本就是lists吗 怎麽变成tuple
----------------------------------
http://i.imgur.com/lkRhUSK.png
3.
#links[0].get('href') #'ht//example.com/lacie'
#links[0].contents # ['Lacie']
请问这种取出内容物的方法是怎麽知道的
书上没写links[0].get('href')的话 我不会知道它可以这样用
-----------------------------
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都不会显示
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 49.159.113.68
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1490332669.A.945.html
1F:推 Czero: 第二个不是links[1]吗 03/24 13:21
2F:→ liang1230: 你先学好基本语法吧 03/24 21:35
3F:→ s860134: matlab 或是 numpy 的後遗症XD 03/24 21:47
4F:推 jn8029: 感觉是基本语法还没学就想直接硬干爬虫XD 03/25 05:00