1.今天抓取某网站的数据时,显示报错UnboundLocalError: local variable 'title' referenced before assignment
"""
Traceback (most recent call last):
File "E:/work/spider/main.py", line 5, in <module>
spider.get_product_urls()
File "E:\work\spider\product.py", line 28, in get_product_urls
self.crawl(url,num,proxy)
File "E:\work\spider\product.py", line 45, in crawl
pages,product_list = parse.parse_product()
File "E:\work\spider\parse_html.py", line 96, in parse_product
"product_name":product_name,
UnboundLocalError: local variable 'product_name' referenced before assignment
"""
2.回到 代码中并未发现变量的问题,再次测试发现是代理ip失效了导致用xpath获取到的数据错误未能提取到名称数据
3.如果解决不了回到代码中寻找变量名称看看是不是变量的问题