我是

Python的新手,我得到这个错误:

Traceback (most recent call last):

File "/usr/local/bin/scrapy", line 4, in

execute()

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scrapy/cmdline.py", line 130, in execute

_run_print_help(parser, _run_command, cmd, args, opts)

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scrapy/cmdline.py", line 96, in _run_print_help

func(*a, **kw)

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scrapy/cmdline.py", line 136, in _run_command

cmd.run(args, opts)

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scrapy/commands/crawl.py", line 42, in run

q = self.crawler.queue

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scrapy/command.py", line 31, in crawler

self._crawler.configure()

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scrapy/crawler.py", line 36, in configure

self.spiders = spman_cls.from_settings(self.settings)

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scrapy/spidermanager.py", line 33, in from_settings

return cls(settings.getlist('SPIDER_MODULES'))

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scrapy/spidermanager.py", line 23, in __init__

for module in walk_modules(name):

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scrapy/utils/misc.py", line 65, in walk_modules

submod = __import__(fullpath, {}, {}, [''])

File "/my_crawler/empt/empt/spiders/empt_spider.py", line 59

check_exists_sql = "SELECT * FROM LINKS WHERE link = '%s' LIMIT 1" % item['link']

^

IndentationError: unexpected indent

在这一点代码:

def parse_item(self, response):

hxs = HtmlXPathSelector(response)

sites = hxs.select('//a[contains(@href, ".mp3")]/@href').extract()

items = [ ]

#for site in sites:

#link = site.select('a/@href').extract()

#print site

for site in sites:

item = EmptItem()

item['link'] = site #site.select('a/@href').extract()

#### DB INSERT ATTEMPT ###

#MySQL Test

#open db connection

db = MySQLdb.connect("localhost","root","str0ng","TESTDB")

#prepare a cursor object using cursor() method

cursor = db.cursor()

#see if any links in the DB match the crawled link

check_exists_sql = "SELECT * FROM LINKS WHERE link = '%s' LIMIT 1" % item['link']

cursor.execute(check_exists_sql)

if cursor.rowcount = 0:

#prepare SQL query to insert a record into the db.

sql = "INSERT INTO LINKS ( link ) VALUES ( '%s')" % item['link']

try:

#execute the sql command

cursor.execute(sql)

#commit your changes to the db

db.commit()

except:

#rollback on error

db.rollback()

#fetch a single row using fetchone() method.

#data = cursor.fetchone()

#print "Database version: %s " % data

#disconnect from server

db.close()

### end mysql

items.append(item)

return items​

python意外缩进引发逻辑错误_python – IndentationError:意外的缩进错误相关推荐

  1. python控制代码块逻辑关系_Python 编程中用代码缩进表示逻辑递进关系,通常用几个空格_学小易找答案...

    [判断题]在自动化现场的跟踪过程中,钢板的数据定义可以定义为一个类(class),现场的每一块钢板称为一个实例. [多选题]下列Python语句正确的是 [判断题]四联球菌.八叠球菌.葡萄球菌均是多细 ...

  2. 【python :编译错误】 IndentationError:unexpected indent(缩进问题)

    转载:python :脚本运行出现语法错误:IndentationError:unexpected indent(缩进问题) 转载:TRACEING [问题]  一个python脚本,本来都运行好好的 ...

  3. python意外缩进引发逻辑错误_如何编写 Python 程序

    如何编写 Python 程序 从今以后,保存和运行 Python 程序的标准步骤如下: 对于 PyCharm 用户 打开 PyCharm. 以给定的文件名创建新文件. 输入案例中给出的代码. 右键并运 ...

  4. python :脚本运行出现语法错误:IndentationError:unexpected indent(缩进问题)

    原文转载: https://www.jb51.net/article/153879.htm 今天在网上copy的一段代码,代码很简单,每行看起来该缩进的都缩进了,运行的时候出现了如下错误,Indent ...

  5. python报错输出到日志_Python下的异常处理及错误日志记录

    Python使用被称为异常的特殊对象来表达执行期间发现的错误.当这些异常没有被捕获并处理时,程序将停止,并向控制台打印错误信息.这个错误信息通常是一个traceback,包含了异常的类型,以及诱发这个 ...

  6. python urlopen错误_Python:URLError:urlopen错误[Errno 10060]

    操作系统:Windows 7; 使用Python GUI Shell的Python 2.7.3 我正在尝试通过Python阅读网站,并且有多个作者使用urllib和urllib2库.要将网站存储在变量 ...

  7. python语言中的缩进是什么意思_python编程中的缩进是什么意思

    Python最具特色的是用缩进来标明成块的代码.我下面以if选择结构来举例.if后面跟随条件,如果条件成立,则执行归属于if的一个代码块. 下面对比C语言来看一下if ( i > 0 ) { x ...

  8. python中gmtime的hour错误_python中gmtime的hour错误_在Python中操作日期和时间之gmtime()方法的使用...

    python中datetime怎么用广告总是在最精彩的时候出现,你总是在小编爱的最深的时候离开. ''''' 日期相关的操作 ''' from datetime import datetime fro ...

  9. python中eof表示什么语句错误_python中pickle的EOF错误

    根据这些评论,我对最有可能的问题有一个猜测,但至少有50%的可能性我猜错了,在这种情况下--告诉我,我会删除答案.在 我猜你是在尝试使用流套接字,就好像它是一个消息序列一样.这是网络编程新手中非常常见 ...

最新文章

  1. 0.0 目录-深度学习第五课《序列模型》-Stanford吴恩达教授
  2. c语言uint赋值给int,如何在C#中将uint转换为int?
  3. 自然语言处理笔记-哈工大 关毅
  4. vim语法高亮的错误解决办法
  5. css selector的优先级
  6. Java并发编程面试题(2020最新版)
  7. 去快捷方式小箭头_电脑桌面如何快速去掉快捷方式小箭头
  8. js检测是否安装java_js判断当前浏览器是否是源生app的webview
  9. 10.14-10.20学习总结
  10. 微信小程序跳转微信小程序的实现
  11. vb与mysql实现登录界面_VB连接SQL数据库做用户登录窗口
  12. 向jupyter notebook插入图片并控制大小和对齐方式
  13. 云计算概念:什么是云计算
  14. X-Frame-Options
  15. python数据分析(一):导入数据、描述统计、交叉分析、相关分析、线性回归分析
  16. 感恩与祝福——与巴铁兄弟的友情告别
  17. Android蓝牙系统框架和代码结构
  18. 第四届vex机器人亚洲锦标赛_站在亚洲之巅丨上实剑桥国际高中吴霖哲同学斩获VEX机器人亚洲锦标赛金奖...
  19. 20200404-斜坡补偿
  20. Red Giant Magic Bullet Suite介绍

热门文章

  1. LeetCode 443. 压缩字符串(双指针)
  2. POJ 2287 田忌赛马(贪心)
  3. 【Python基础知识-pycharm版】第二节-赋值/数据类型/时间点/运算符/字符串
  4. html里span和div,HTML div和span
  5. caffe模型文件解析_Caffe ImageData神经网络基本示例无法解析模型文件
  6. 猪八戒背媳妇用计算机弹出来,猪八戒背媳妇?杭城游泳馆爆笑一幕:浙大学霸果然机智!...
  7. 丹琦女神新作:对比学习,简单到只需要Dropout两下
  8. 人物志 | KDD Cup 2017双料冠军燕鹏
  9. 复杂语境下的实体关系抽取
  10. python 判断一个点(坐标)是否在一个多边形内利用射线法