BeautifulSoup4的安装及使用

电脑杂谈  发布时间:2020-03-19 03:02:09  来源:网络整理

用beautifulsoup爬网页_beautifulsoup怎么用_beautifulsoup 安装

如:soup.title

#

soup.p

#

The Dormouse's story

soup.a(注:仅仅返回第一个结果)

beautifulsoup 安装_用beautifulsoup爬网页_beautifulsoup怎么用

# Elsie

soup.find_all('a') (find_all 可以返回所有)

# [Elsie,

# Lacie,

# Tillie]

find还可以按属性查找

beautifulsoup怎么用_beautifulsoup 安装_用beautifulsoup爬网页

soup.find(id="link3")

# Tillie

要取某个标签的某个属性beautifulsoup怎么用,可用变量有 find_all,get

for link insoup.find_all('a'):

print(link.get('href'))

#

beautifulsoup 安装_用beautifulsoup爬网页_beautifulsoup怎么用

#

#

要取html文件中的所有文本beautifulsoup怎么用,可使用get_text()

print(soup.get_text())

# TheDormouse's story

# TheDormouse's story

beautifulsoup怎么用_用beautifulsoup爬网页_beautifulsoup 安装

# Once upona time there were three little sisters; and their names were

#Elsie,

# Lacieand

#Tillie;

# and theylived at the bottom of a well.

# ...

如果是打开html文件,语句可用:

soup =BeautifulSoup(open("index.html"))

BeautifulSoup中的Object


本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-144654-1.html

    相关阅读
      发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

      • 张晓晨
        张晓晨

        文化上

      • 李晓静
        李晓静

        对中国大部分地区来说问题不是环保

      热点图片
      拼命载入中...