scrapy 爬一个网站,如:http://xxx.org/,遇到了一个链接是 http://xxx.org/新闻,
发现这个链接,在 scrpay print 话能输出到 shell 里,在 scrapy shell 里用 sel.xpath("//@href"),也能筛选到,但是在入 mysql 的时候,只能存入这个中文链接前的 url 链接,这个是 python2 的 unicode 问题么?
def parse(self, response):
conn = MySQLdb.connect(host="localhost",user="root",passwd="root",db="url")
cur = conn.cursor()
for sel in response.xpath('//@href').extract():
x = sel
cur.execute('insert into urlsinfo (url) values(%s)',x)
conn.commit()
cur.close()
代码略丑,勿喷。 刚学习 scrapy ,你们都是怎么解决这个问题的?