taotaogoudan
2017-08-16 08:57
采纳率: 100%
浏览 3.1k
已采纳

python 使用BeautifulSoup 出错

import requests, bs4
res= requests.get(r'http://www.baidu.com')
nostarchsoup=bs4.BeautifulStoneSoup(res.text)
type(nostarchsoup)

结果显示:
UserWarning: The BeautifulStoneSoup class is deprecated. Instead of using it, pass features="xml" into the BeautifulSoup constructor.
'The BeautifulStoneSoup class is deprecated. Instead of using '

这是怎么回事呀?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • 图图和牛爷爷 2017-08-21 07:03
    已采纳

    nostarchsoup=bs4.BeautifulSoup(res.text,'html.parser')这样写

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • oyljerry 2017-08-16 09:48

    用bs3

     import urllib2
    from BeautifulSoup import BeautifulStoneSoup #Using bs3
    
    url="https://api.projectnimbus.org/neaodataservice.svc/NowcastSet"
    request = urllib2.Request(url)
    request.add_header("accept", "*/*")
    request.add_header('AccountKey', "OSJeROQjTg4v7Ec3kiecjw==")
    request.add_header('UniqueUserID', "00000000000000000000000000000001")
    result = urllib2.urlopen(request)
    xml_str = result.read()
    
    soup = BeautifulStoneSoup(xml_str)
    
    prop_list = []
    for content in soup.findAll("m:properties"):
        props = {}
        for prop in content.findChildren():
            props[prop.name[2:]] = prop.text
        prop_list.append(props)
    
    for prop in prop_list:
        print "Area: %(area)s\nLat: %(latitude)s\nLong: %(longitude)s\n" % prop
    
    评论
    解决 无用
    打赏 举报
  • 坎沛尔麦斯达 2019-11-27 11:36

    ‘bs4.BeautifulStoneSoup’改为‘bs4.BeautifulSoup'

    bs4.BeautifulSoup(res.text,'html.parser')

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题