网址:
中国审判流程信息公开网:https://splcgk.court.gov.cn/gzfwww/
所抓取到的数据:
环境:
Python 3.7
Mac OS
Github代码下载:
https://github.com/Minotgeogry/law_web_open_source_crawl_python
代码示例:
1.导入数据库
import requests #数据抓取模块
from parsel import Selector #标签解析模块
import pymysql #数据库模块
import html #网页解析模块
import re #正则
import json #jason模块
# 连接数据库及建表函数
def create():
connect = pymysql.connect(host="127.0.0.1", #数据库地址,一般为127.0.0.1或者localhost
port=3306, #数据库端口
user={
databaseaccount}, #数据库账户
password={
password}, #数据库密码
database={
databasename}, #数据库名称
charset="utf8") #数据库字符集,可略去
cursor = connect.cursor() #创建游标对象cursor
cursor.execute("drop table if exists law_list") #使用 execute() 方法执行 SQL,若同名表存在则删除
sql = """ create table law_list(
id int not null auto_increment primary key comment '序号',
case_id varchar(255) not null comment 'cBh 案件编码',
case_num varchar(255) not null comment 'cBt 案件编号',
case_name varchar(255) not null comment 'cFymc 案件标题',
case_date date not null comment 'dtUpdatetime 案件时间',
case_url varchar(255) not null comment '案件网址',
case_text longtext not null comment '案件内容'
) engine=InnoDB default charset=utf8""" #建表
cursor.execute(sql) #执行语句
connect.close() #关闭连接
# 插入数据函数
def insert(value):
connect = pymysql.connect(host='127.0.0.1',
port=3306,
user={
databaseaccount},
password=