python之scrapy爬虫入门

代码

爬取赶集网二手房数据

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爬虫入门)