zoukankan      html  css  js  c++  java
  • Python3.X BeautifulSoup([your markup], "lxml") markup_type=markup_type))的解决方案

     1 random.seed(datetime.datetime.now())
     2 def getLinks(articleUrl):
     3     html = urlopen("http://en.wikipedia.org"+articleUrl)
     4     bsOdj = BeautifulSoup(html)
     5     return bsOdj.find("div",{"id":"bodyContent"}).findAll("a",href=re.compile("^(/wiki/)((?!:).)*$"))
     6 links = getLinks("/wiki/Kevin_Bacon")
     7 while len(links) > 0:
     8     newArticle = links[random.randint(0,len(links)-1)].attrs["href"]
     9     print(newArticle)
    10     links = getLinks(newArticle)

    这是我的源代码,然后报了警告

    D:Anaconda3libsite-packagess4__init__.py:181: UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("lxml"). 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.
    
    The code that caused this warning is on line 16 of the file D:/ThronePython/Python3 网络数据爬取/BeautifulSoup 爬虫_开始爬取/BeautifulSoup 维基百科六度分割_构建从一个页面到另一个页面的爬虫.py. To get rid of this warning, change code that looks like this:
    
     BeautifulSoup([your markup])
    
    to this:
    
     BeautifulSoup([your markup], "lxml")
    
      markup_type=markup_type))

    百度后发现,其实这是没有设置默认的解析器造成的,

    根据提示设置解析器即可,否则则采取默认的解析器,将第四行改为:

        bsOdj = BeautifulSoup(html,"lxml")

    即可.

    我的csdn博客地址:http://blog.csdn.net/fontthrone/article/details/70429776

  • 相关阅读:
    HTML文本格式化与HTML 超链接
    html知识杂记
    常用的默认函数
    js条件语句初步练习
    DevOps之docker自动化部署web应用
    DevOps之docker自动化部署java应用
    hive应用基础知识备忘
    hive应用-离线数据仓库分层模型
    hive基础-数据模型
    hive基础-组件介绍
  • 原文地址:https://www.cnblogs.com/fonttian/p/6596795.html
Copyright © 2011-2022 走看看