InterfaceError:(sqlte3.InterfaceError)Error bindin

2019-07-18 05:07发布

Recently, I used Python and Scrapy to crawl article information like 'title' from a blog. Without using a database, the results are fine / as expected. However, when I use SQLalchemy, I received the following error:

InterfaceError:(sqlite3.InterfaceError)Error binding parameter 0 -probably unsupported type.[SQL:u'INSERT INTO myblog(title) VALUES (?)'] [PARAMETERS:([u'\r\n Accelerated c++\u5b66\u4e60
chapter3 -----\u4f7f\u7528\u6279\u636e \r\n '],)]

My xpath expression is:
item['title'] = sel.xpath('//*[@class="link_title"]/a/text()').extract()

Which gives me the following value for item['title']:
[u'\r\n Accelerated c++ \u5b66 \u4e60 chapter3 -----\u4f7f\u7528\u6279\u636e \r\n ']

It's unicode, why doesn't sqlite3 support it? This blog's title information contains some Chinese. I am a tired of sqlalchemy. I've referred its documents, but found nothing, and I'm out of ideas.

1条回答
Lonely孤独者°
2楼-- · 2019-07-18 05:26

The problem that you're experiencing is that SQLite3 wants a datatype of "String", and you're passing in a list with a unicode string in it.

change:
item['title'] = sel.xpath('//*[@class="link_title"]/a/text()').extract()
to
item['title'] = sel.xpath('//*[@class="link_title"]/a/text()').extract()[0].

You'll be left with a string to be inserted, and your SQLite3 errors should go away. Warning, though, if your ever wanting to deal with more than just one title, this will limit you to the first. You can use whatever method you want to persuade those into being a string, though.

查看更多
登录 后发表回答