python 爬虫使用到bs4的介绍

python 爬虫使用到bs4的介绍,第1张

bs4是对某些内容做逻辑的提取,比如html文件,xml,json格式的数据

bs4: 的安装 >pip install --user bs4

使用:

from bs4 import BeautifulSoup

page = BeautifulSoup(data,"html.parser") #指定html解释器

#2。从bs4 找数据  find(标签 ,属性=值) find_all(标签 ,属性=值)

table=page.find('div',class_="news-nr-box")
#class是python的关键字,

trs = table.find_all('tr',align="center",bgcolor="#FFFFFF")
 
for tr in trs:
    tds = tr.find_all('td')
    name = tds[0].text#.text 表示提取到被标签标记的内容
    high = tds[1].text
    low = tds[2].text
    xianjia = tds[3].text
    danwei = tds[4].text
    date = tds[5].text
   

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/885252.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-14
下一篇2022-05-14

发表评论

登录后才能评论

评论列表(0条)

    保存