爬虫地址
http://www.boc.cn/sdbapp/rwmerchant/sra32/
设计技术
- requests请求页面
- re正则表达式
- xpath语法解析html对象
爬虫思路
- 爬虫开始
- 先找到大类,大类比如:
- 每一个大类找到分页的链接
- 解析每一个分页的链接里面的商店的链接
- 对每一个商店的链接进行抓取和解析
- 爬虫结束
爬虫代码
#-*-coding:utf-8-*-
import json
import os
import re
import time
import lxml
import requests
import xlrd
import xlwt
from lxml import etree
from xlutils.copy import copy
def get_page(url):
try:
response= requests.get(url)
if response.status_code==200:
return response
except:
return None
def parse_detail_page(detail_html):
company_name=''.join(detail_html.xpath('//td[@colspan="3"]/text()'))
try:
company_address = detail_html.xpath('//td[@colspan="5"]/text()')[0]
except:
company_address=''
try:
company_phone = detail_html.xpath('//td[@colspan="5"]/text()')[1]
except: