美文网首页
python之scrapy爬虫入门

python之scrapy爬虫入门

作者: 程序员进阶 | 来源:发表于2017-11-01 17:56 被阅读15次

代码

爬取赶集网二手房数据

scrapy shell http://hz.ganji.com/fang1/shangcheng/

view(response)

获取一个值:

response.xpath(".//*[@id='puid-2929419083']/dl/dd[5]/div[1]/span[1]/text()").extract()

获取一个列表:

response.xpath(".//div[@class='f-list-item ']/dl/dd[5]/div[1]/span[1]/text()").extract()

response.xpath(".//div[@class='f-list-item ']/dl/dd[1]/a/text()").extract()

scrapy list

scrapy crawl zufang

此处是python2和3的坑:

使用ipython建数据库表:

ipython = python -m IPython

import sqlite3

zufang = sqlite3.connect('zufang.sqlite')

create_table = 'create table zufang(title varchar(512),money varchar(128))'

zufang.execute(create_table)

exit

相关文章

网友评论

      本文标题:python之scrapy爬虫入门

      本文链接:https://www.haomeiwen.com/subject/cnmgpxtx.html