• python 之beautiful soup 4 warning


    在使用beautifulsoup4时出现此警告,必应后找到如下解决方案:

    UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("html.parser"). 
    This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, 
    it may use a different parser and behave differently.

    UserWarning:没有明确指定解析器,因此我正在使用该系统的最佳可用HTML解析器(“html.parser”)。
    这通常不是问题,但是如果您在另一个系统或不同的虚拟环境中运行此代码,
    它可能会使用不同的解析器并且行为不同。

    解决办法:指定HTML解析器

    from urllib.request import urlopen
    from bs4 import BeautifulSoup
    html = urlopen("http://www.pythonscraping.com/pages/warandpeace.html")
    bsObj = BeautifulSoup(html,'html.parser')
    namelist=bsObj.findAll('span',{'class':'green'})
    for name in namelist:
        print(name.get_text())

    bsobj=BeautifulSoup(html,'html.parser')

    完成。

  • 相关阅读:
    Python基础之初始编码
    Excel图表编辑---表格移动,样式修改
    Python基础之Python的变量、常量
    刷题62. Unique Paths
    刷题56. Merge Intervals
    刷题55. Jump Game
    刷题53. Maximum Subarray
    刷题49. Group Anagrams
    刷题48. Rotate Image
    刷题46. Permutations
  • 原文地址:https://www.cnblogs.com/frank1126lin/p/9102523.html
Copyright © 2020-2023  润新知