python 爬虫 CSS 出现错误IndexError: list index out of range

html-css013

python 爬虫 CSS 出现错误IndexError: list index out of range,第1张

Traceback (most recent call last):

File "D:\Program Files (x86)\JetBrains\PyCharm Educational Edition 1.0.1\helpers\pydev\pydev_run_in_console.py", line 66, in <module>

globals = run_file(file, None, None)

File "D:\Program Files (x86)\JetBrains\PyCharm Educational Edition 1.0.1\helpers\pydev\pydev_run_in_console.py", line 28, in run_file

pydev_imports.execfile(file, globals, locals) # execute the script

File "D:/python/xpth/xpathPractice.py", line 51, in <module>

results = pool.map(spider, page)

File "D:\anzhuang\Anaconda\lib\multiprocessing\pool.py", line 251, in map

return self.map_async(func, iterable, chunksize).get()

File "D:\anzhuang\Anaconda\lib\multiprocessing\pool.py", line 558, in get

raise self._value

IndexError: list index out of range123456789101112123456789101112

出现如上所示的错误:

IndexError 下标索引超出序列边界,比如当x只有三个元素,却试图访问x[5]

你的python爬虫界面和博主的不一样,很可能是因为你所用的python爬虫版本和博主所用的版本不同所致。此外,网页上可能还有一些css代码和javascript代码等对爬虫界面造成影响,你可以尝试更新你的爬虫版本,并根据网页代码来调整你的爬虫设置。你的python爬虫界面和博主的不一样,很可能是因为你所用的python爬虫版本和博主所用的版本不同所致。此外,网页上可能还有一些css代码和javascript代码等对爬虫界面造成影响,你可以尝试更新你的爬虫版本,并根据网页代码来调整你的爬虫设置。

4种方法可以定位爬虫位置:1、传统 BeautifulSoup 操作经典的 BeautifulSoup 方法借助 from bs4 import BeautifulSoup,然后通过 soup = BeautifulSoup(html, "lxml") 将文本转换为特定规范的结构,利用 find 系列方法进行解析。2、基于 BeautifulSoup 的 CSS 选择器这种方法实际上就是 PyQuery 中 CSS 选择器在其他模块的迁移使用,用法是类似的。关于 CSS 选择器详细语法可以参考:http://www.w3school.com.cn/cssref/css_selectors.asp 由于是基于 BeautifulSoup 所以导入的模块以及文本结构转换都是一致的。3、XPathXPath 即为 XML 路径语言,它是一种用来确定 XML 文档中某部分位置的计算机语言,如果使用 Chrome 浏览器建议安装 XPath Helper 插件,会大大提高写 XPath 的效率。4、正则表达式如果对 HTML 语言不熟悉,那么之前的几种解析方法都会比较吃力。这里也提供一种万能解析大法:正则表达式,只需要关注文本本身有什么特殊构造文法,即可用特定规则获取相应内容。依赖的模块是re希望以上回答可以帮助到你。