2.2 再端一碗BeautifulSoup

2019-08-06  本文已影响0人  modao233

掌握BeautifulSoup的基本用法


from urllib.request import urlopen
from bs4 import BeautifulSoup

html = urlopen("http://pythonscraping.com/pages/warandpeace.html")
bsObj = BeautifulSoup(html.read(), "html.parser")

# nameList = bsObj.findAll("span", {"class" : "green"}, limit=10)
# for name in nameList:
#     print(name.get_text())

# nameList = bsObj.findAll(text = "the prince")
# print(len(nameList))

allText = bsObj.findAll(id = "text")
print(allText[0].get_text())
上一篇下一篇

猜你喜欢

热点阅读