BeautifulSoup不能完整识别网页html代码
来源:互联网 发布:sql server数据库备份 编辑:程序博客网 时间:2024/06/05 07:25
环境:Python版本:2.7.3
>>> html = gethtml('http://www.joiway.com/')>>> soup = BeautifulSoup(html)>>> soup.find_all("a",href=True)[]>>> soup.find_all("a")[]>>> soup.find_all("link")[<link href="http://oss.aliyuncs.com/jianzhimao/web-res/icon/jianzhimao-logo-min.png" rel="icon" type="image/x-icon"/>, <link href="http://oss.aliyuncs.com/jianzhimao/web-res/icon/jianzhimao-logo-min.png" resl="shortcut icon" type="image/x-icon"/>, <link href="/templets/default/style/style.css" rel="stylesheet" type="text/css">\n<!--\u2013[if lt IE9]-->\n<script>\n(function() {\n if (!\n /*@cc_on!@*/\n 0) return;\n var e = "abbr, article, aside, audio, canvas, datalist, details, dialog, eventsource, figure, figcaption, footer, header, hgroup, main, mark, menu, meter, nav, output, progress, section, time, video".split(', ');\n var i= e.length;\n while (i--){\n document.createElement(e[i])\n }\n})()\n</script>\n</link>]
如上,soup.find_all()找不到a标签,然而用chrome查看该网站源码是存在a标签的,gethtml(源码就不贴了)函数运作也没问题,单独打印soup发现只解析了部分html代码.
问题的原因:没有安装第三方的HTML解析器,所以用的是默认的解析器。而Python 2.7.3的默认解析器存在文档容错能力差的毛病。
解决方法: pip install html5lib (或者 lxml)
参考:https://www.crummy.com/software/BeautifulSoup/bs4/doc/index.zh.html#id5
0 0
- BeautifulSoup不能完整识别网页html代码
- python : BeautifulSoup 网页HTML 解析器
- 网页打印完整代码
- python︱HTML网页解析BeautifulSoup学习笔记
- Python获取网页内容、使用BeautifulSoup库分析html
- HTML网页代码大全
- 北京时间网页html代码
- html网页详细代码
- html 网页代码
- html 无缝轮播图完整代码
- Flex嵌入完整的html网页
- Android 实现语音识别的完整代码
- 基于opencv车牌识别项目完整代码
- BeautifulSoup解析网页信息
- beautifulsoup 解析网页内容
- BeautifulSoup解析网页
- 【爬虫】BeautifulSoup解析网页
- C#根据特定URL网址获取网页源码(完整html代码)后用正则式匹配得到目标串
- MFC: 获得关机消息;阻止Windows关机
- Runloop的最简单使用
- web界面设计的原则和总结
- angularjs http 无刷新调用
- Android基础之CountDownLatch
- BeautifulSoup不能完整识别网页html代码
- 操作符重载 – 下 --- 用 成员函数 来重载操作符
- react-native-code-push与cocoapods pod 'SSZipArchive'冲突
- 关键字typedef与#define的异同
- 修改Tomcat默认端口号
- Python爬虫实战之爬取链家广州房价_01简单的单页爬虫
- if和switch的区别
- 很详细的java反射机制讲解
- 大家好,怎样对网站做优化?都有哪些手段? (谷歌)