python网络爬虫使用BeautifulSoup时出现findAll执行失败问题分析
来源:互联网 发布:读写数据什么意思 编辑:程序博客网 时间:2024/06/17 04:20
最近在学习和演技python网络爬虫,并且使用了BeautifulSoup进行格式化查找。在使用Python读取word文档的时候,由于在Linux环境下读取Word文档,需要先将word文档转换为xml文档,在使用findAll函数进行文档内容定位时。findAll执行无结果。经过分析和问题查找,发现是由于为将BeautifulSoup的解析器指定为xml,导致后续的查找失败。修改后的代码片段如下:
from zipfile import ZipFilefrom urllib.request import urlopenfrom io import BytesIOfrom bs4 import BeautifulSoupwordFile=urlopen("http://pythonscraping.com/pages/AWordDocument.docx").read()wordFile=BytesIO(wordFile)document=ZipFile(wordFile)xml_content=document.read('word/document.xml')wordObj=BeautifulSoup(xml_content.decode('utf-8'),"xml")textString=wordObj.findAll("w:t")for textElem in textString: print(textElem.text)
阅读全文
2 0
- python网络爬虫使用BeautifulSoup时出现findAll执行失败问题分析
- python网络爬虫-使用BeautifulSoup
- Python爬虫:BeautifulSoup的find()和findAll()
- Python-网络爬虫之BeautifulSoup
- 使用python语言结合beautifulsoup编写简单的网络爬虫
- 使用requests+beautifulsoup模块实现python网络爬虫功能
- 使用requests+beautifulsoup模块实现python网络爬虫功能
- Python使用BeautifulSoup进行爬虫
- Python-网络爬虫之BeautifulSoup(1)
- Python-网络爬虫之BeautifulSoup(2)
- Python网络爬虫之BeautifulSoup库
- python网络爬虫-正则表达式和BeautifulSoup
- python 网络爬虫学习笔记之beautifulsoup
- python - BeautifulSoup中的find()和findAll()
- Python的BeautifulSoup的find()和findAll()
- Python爬虫(2)--BeautifulSoup的使用
- 网络爬虫:BeautifulSoup
- 网络爬虫之beautifulsoup
- GYM
- apk安装出现闪退java.lang.RuntimeException: Unable to instantiate application
- VSCode 调试tolua(xlua、slua、ulua通用)
- eclipse程序更改但结果运行无反应
- DiscuzX3.2目录解析
- python网络爬虫使用BeautifulSoup时出现findAll执行失败问题分析
- Linux-profile、bashrc、bash_profile之间的区别和联系
- Spring简要总结
- BZOJ 1072 [SCOI2007]排列perm (状态压缩+dp+同余定理)
- 正则简介
- ubootenv工具fw_printenv及配置文件fw_env.config
- Vi/Vim查找替换使用方法
- WSAEventSelect事件模型函数介绍
- 集合