--甘肃省公示系统爬虫  
--http://xygs.gsaic.gov.cn/gsxygs/

--引用公用包
local com=require "res.util.comm"
local ecps=require "res.util.ecps"
local json=require "json"
--名称
spiderName="甘肃公示爬虫";
--代码
spiderCode="ecps_gs";
--是否下载3级页
spiderDownDetailPage=true;
--开始下载页
spiderStartPage=1;
--最大下载页
spiderMaxPage=1;
--上次下载时间
spiderLastDownloadTime="2016-01-01 01:01:01";
--执行频率30分钟
spiderRunRate=30;

--下载内容写入表名
spider2Collection="ecps";
--下载页面时使用的编码
spiderPageEncoding="UTF8";
--是否使用代理
spiderUserProxy=false;
--是否是安全协议
spiderUserHttps=false;
--下载详细页线程数
spiderThread=1
--存储模式 1 直接存储，2 调用消息总线 ...
spiderStoreMode=1
spiderStoreToMsgEvent=1 --消息总线event
--延时毫秒 基本延时(spiderSleepBase)+随机延时(spiderSleepRand)
spiderSleepBase=100
spiderSleepRand=100
--判重字段 空默认不判重，spiderCoverAttr="title" 按title判重覆盖
spiderCoverAttr="title"

yzm=""
cookies3=""
--取得对方网站最后发布时间 必须返回yyyy-MM-dd HH:mm:ss 格式
function getLastPublishTime()
	return os.date("%Y-%m-%d %H:%M:%S", os.time())
end



--下载分析列表页
function downloadAndParseListPage(pageno) 

	
	
	local entMl=getEntNames("ecps_gs")
	--local entMl={}
	print("甘肃企业名录长度:",tostring(table.getn(entMl)))
	
return entMl
--测试代码
--	local entMl={}
--	for i=1,1 do
--				item={}
--				item["title"]="兰州利源建设工程招标有限责任公司"
--				--item["title"]="甘肃通汇汽车销售服务有限公司"
--				item["href"]="http://xygs.gsaic.gov.cn/gsxygs/securitycode.jpg" --验证码
--				table.insert(entMl,item)
				
--	end
--	return entMl
--测试代码结束
	
end

function downloadDetailPage(data)
	data["href"]="http://xygs.gsaic.gov.cn/gsxygs/securitycode.jpg"--验证码
	print("开始下载  ",data["title"],"  公示数据")
	for i=1,20 do
		local downloadId=changeDownloader()
		print("甘肃切换下载点:",downloadId)
		for j=1,1 do
			local headIndex={
				["Accept"]="text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
				["Accept-Encoding"]="gzip,deflate,sdch",
				["Accept-Language"]="zh-CN,zh;q=0.8,en;q=0.6,zh-TW;q=0.4",
				["Upgrade-Insecure-Requests"]="1",
				["Host"]="xygs.gsaic.gov.cn",
				["User-Agent"]="Mozilla/.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.130 Safari/537.36"	
			}
			local content,cookies = downloadAdv("http://xygs.gsaic.gov.cn/gsxygs/","get",{},headIndex,"")
			if content=="" then 
				print("访问甘肃首页出错")
				--timeSleep(8)
				break
			end
			local tmp=string.sub(cookies,1,string.len(cookies)-1)..","
			--print("tmp:",tmp)
			if yzm=="" and cookies3=="" then
				print("开始下验证码: "..data["title"])
				local code,cookies2= getCode(data["href"],cookies)
				if code=="error" then
					break
				end
				--print("cookies2:",cookies2)
				local obj2=json.decode(cookies2)
				--printf("obj2:",obj2)				
				--print("obj2 length:",table.getn(obj2))
				yzm=code
				if table.getn(obj2)==1 then
					local tmp2=string.sub(cookies2,2,string.len(cookies2))
					cookies3=tmp..tmp2
				else
					cookies3=cookies2
				end
				print("获取到验证码,开始校验"..code,"  ",data["title"])
			end
			
				
			
			data["title"]=com.trim(data["title"])
			local isSuccess,regNo,entcate=codeCheck(cookies3,data["title"],yzm)
			if isSuccess=="true" then
				local entInfo={}
					getEntDetail(regNo,entcate,cookies3,entInfo)
					--去冗余字段
					entInfo["pripid"]=nil
					entInfo["href"]=nil
					entInfo["publishtime"]=nil
					data["href"]=nil
					local b=checkData(data["title"],entInfo)
--					return entInfo
						if  b	then
							return entInfo
						else
							break
						end
			elseif isSuccess=="error" then
				timeSleep(8)
				break
			elseif isSuccess==nil then
				print(data["title"].."  无此企业!")
				saveErrLog(spiderCode,spiderName.."_title",data["title"],err)
				return nil
			else
				yzm=""
				cookies3=""
				--print("验证码错误,重新请求.....")
				break
			end
		end
	end
end

function getCode(href,cookies)
	local head={
			["Accept"]="image/webp,image/*,*/*;q=0.8",
			["Accept-Encoding"]="gzip,deflate,sdch",
			["Accept-Language"]="zh-CN,zh;q=0.8,en;q=0.6,zh-TW;q=0.4",
			["Cache-Control"]="no-cache",
			["Host"]="xygs.gsaic.gov.cn",
			["Pragma"]="no-cache",
			["Referer"]="http://xygs.gsaic.gov.cn/gsxygs/main.jsp",
			["User-Agent"]="Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36"	
	}
	--print(href,cookies)
	local content,cookies2= downloadAdv(href.."?v="..tostring(os.time()),"get",{},head,cookies)
	if string.find(content,"<html>")~=nil then
		print("获取验证码图片出错")
		return "error"
	end
	
	
	--print("获取到图片：",content)
	if content=="" then
		print("获取验证码图片出错")
		return "error"
	end
	local code= getEcpsCode("gs",content)
	return code,cookies2
end

function codeCheck(cookies,title,code)
	--print("cookies:",cookies)
	local codeCheckUrl="http://xygs.gsaic.gov.cn/gsxygs/pub!list.do"
	local head={
			["Accept"]="text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
			["Accept-Encoding"]="gzip, deflate",
			["Accept-Language"]="zh-CN,zh;q=0.8,en;q=0.6,zh-TW;q=0.4",
			["Content-Type"]="application/x-www-form-urlencoded; charset=UTF-8",
			["Host"]="xygs.gsaic.gov.cn",
			["Origin"]="http://xygs.gsaic.gov.cn",
			["Referer"]="http://xygs.gsaic.gov.cn/gsxygs/pub!list.do",
			["Pragma"]="no-cache",
			["Cache-Control"]="no-cache",
			["X-Requested-With"]="XMLHttpRequest",
			["User-Agent"]="Mozilla/.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.130 Safari/537.36",	
	}
	--print(cookies)
	local param={["authCodeQuery"]=code,["queryVal"]=title}
	local content,_=downloadAdv(codeCheckUrl,"post",param,head,cookies);
	if content=="" then
		print("验证码校验请求失败")
		return "error","",""
	end
	--print(content)
	if string.find(content,"验证码输入错误")~=nil then
		return "false","",""
	end
	
	if string.find(content,"您输入的查询条件有误")~=nil then
		return nil,"",""
	end
	
	
	local regNo=findOneText("div.list li.font16 a:eq(0):attr(id)",content)
	local entcate=findOneText("div.list li.font16 a:eq(0):attr(_entcate)",content)
	print("regNo:",regNo,"entcate:",entcate)
	if regNo~="" and string.len(regNo)>0 then 
		return "true",regNo,entcate
	end
	
	return "false","",""
end






function getEntDetail(regNo,entcate,cookies,entInfo)
	local head={
		["Accept"]="text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
		["Accept-Encoding"]="gzip, deflate",
		["Accept-Language"]="zh-CN,zh;q=0.8",
		["Content-Type"]="application/x-www-form-urlencoded; charset=UTF-8",
		["Host"]="xygs.gsaic.gov.cn",
		["Origin"]="http://xygs.gsaic.gov.cn",
		["Referer"]="http://xygs.gsaic.gov.cn/gsxygs/pub!list.do",
		["Upgrade-Insecure-Requests"]="1",
		["User-Agent"]="Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36"
	}
	
	entInfo["Area"]="GS"
	local url="http://xygs.gsaic.gov.cn/gsxygs/pub!view.do"
	local param={
		["entcate"]=entcate,
		["regno"]=regNo
	}
	local content,_=downloadAdv(url,"post",param,head,cookies)
	
	
	--基本信息
	entInfo=getBaseInfo(content,entInfo)
	--print("基本信息完成")
	--股东信息
	local invertors=getInvertor(content)
	entInfo["invertor"]=invertors
	--print("股东信息完成")
	--变更信息
	local alterInfos=getAlterInfo(content)
	entInfo["alterInfo"]=alterInfos
	--print("变更信息完成")
	--主要人员
	local staffinfos=getStaffinfo(content)
	entInfo["staffinfo"]=staffinfos
	--print("主要人员完成")
	--分支机构
	local childents=getChildent(content)
	entInfo["childent"]=childents
	--print("分支机构完成")
	--行政处罚
	local punishInfos=getPunishInfo(content)
	entInfo["punishInfo"]=punishInfos
	--print("行政处罚完成")
	--经营异常
	local excDirecs=getExcDirec(content)
	entInfo["excDirec"]=excDirecs
	--print("经营异常完成")
	--年报
	local nbtab=getNbList(content,cookies,head)
	if nbtab=="error" then
		print("查询年报列表信息请求出错")
		return "error"
	end
	entInfo["qynb"]=nbtab
	--print("年报完成")
	--os.exit()
	
	
end

function getBaseInfo(content,entInfo)
	local th=findListText("div#jibenxinxi table.detailsList:eq(0) tr th",content)
	local td=findListText("div#jibenxinxi table.detailsList:eq(0) tr td",content)
	--print("th",th)
	local tab={}
	for k,v in pairs(th) do
		if k>1 then
			local tdv=com.trim(td[k-1])
			tab[com.trim(v)]=tdv
			--print(com.trim(v),tab[com.trim(v)])
		end
	end
	local baseinfo=ecps.reversalFormat(tab,ecps.baseFm,ecps.baseMap)
	for k,v in pairs(baseinfo) do
		entInfo[k]=v
		--print(k,v)
	end
	return entInfo
end

function getInvertor(content)
	local investors={}
	local list=findListHtml("table#touziren  tr",content)
	local thead=findOneText("table#touziren tr:eq(0) th:eq(0)",content)
	if string.find(thead,"股东信息")~=nil then
		for k,v in pairs(list) do
			if k>2 then
				local item={}
				item["gdlx"]="td:eq(0)"
				item["gdname"]="td:eq(1)"
				item=findMap(item,"<table>><tr>"..v.."</tr></table>")
				if  item["gdlx"]~=nil then
					--print(item["gdlx"]..item["gdname"])
					local inverstor={}
					inverstor["Inv"]=item["gdname"]
					inverstor["InvTypeName"]=item["gdlx"]
					table.insert(investors,inverstor)
				end
			end
		end
	elseif string.find(thead,"投资人信息")~=nil then
		for k,v in pairs(list) do
			if k>2 then
				local item={}
				item["gdlx"]="td:eq(1)"
				item["gdname"]="td:eq(0)"
				item=findMap(item,"<table>><tr>"..v.."</tr></table>")
				if  item["gdlx"]~=nil then
					--print(item["gdlx"]..item["gdname"])
					local inverstor={}
					inverstor["Inv"]=item["gdname"]
					inverstor["InvTypeName"]=item["gdlx"]
					table.insert(investors,inverstor)
				end
			end
		end
	end
	return investors
end

function getAlterInfo(content)
	local alterInfos={}
	local list=findListHtml("table#changTab tr",content)
	local len=table.getn(list)
	if len>0 then
		for k,v in pairs(list) do 
			
			if k>2 then
				--print(v)
				item={}
				item["AltItemName"]="td:eq(0)"
				item["AltBe"]="td:eq(1)"
				item["AltAf"]="td:eq(2)"
				item["AltDate"]="td:eq(3)"
				item=findMap(item,"<table><tr>"..v.."</tr></table>")
				
				if item["AltDate"]~=nil then
					local alterInfo={}
					alterInfo["AltItemName"]=item["AltItemName"]
					alterInfo["AltAf"]=item["AltAf"]
					alterInfo["AltBe"]=item["AltBe"]
					alterInfo["AltDate"]=item["AltDate"]
					--print(alterInfo["AltItemName"],alterInfo["AltBe"],alterInfo["AltAf"])
					table.insert(alterInfos, alterInfo)	
				end
			end
		end
	end
	return alterInfos
end


function getStaffinfo(content)
	local staffinfos={}
	local list=findListHtml("table#perTab tr",content)
	local thead=findOneText("table#perTab tr:eq(0) th:eq(0)",content)
	if string.find(thead,"主要人员")~=nil then
		local len=table.getn(list)
		if len>0 then
			for k,v in pairs(list) do 
				if k>2 then
					item={}
					item["xm1"]="td:eq(1)"
					item["zw1"]="td:eq(2)"
					item["xm2"]="td:eq(4)"
					item["zw2"]="td:eq(5)"
					item=findMap(item,"<table>><tr>"..v.."</tr></table>")
					--print("第一列:",item["xm1"],item["zw1"])
					local staffinfo={}
					staffinfo["Name"]=item["xm1"]
					staffinfo["Position"]=item["zw1"]
					table.insert(staffinfos,staffinfo)
					if item["xm2"]~=nil and com.trim(item["xm2"])~=""  then
						--print("第二列:",item["xm2"],item["zw2"])
						local _staffinfo={}
						_staffinfo["Name"]=item["xm2"]
						_staffinfo["Position"]=item["zw2"]
						table.insert(staffinfos,_staffinfo)
					end
				end
			end
		end
	end
	return staffinfos
end


function getChildent(content)
	local childents={}
	local list=findListHtml("table#branTab tr",content)
	local len=table.getn(list)
	if len>0 then
		for k,v in pairs(list) do
			if k>2 then
				local item={}
				item["regNo"]="td:eq(1)"
				item["entName"]="td:eq(2)"
				item["regOrgan"]="td:eq(3)"
				item=findMap(item,"<table>><tr>"..v.."</tr></table>")
				local childent={}
				childent["BrName"]=item["entName"]--分支名称
				childent["RegNO"]=item["regNo"]--注册号
				childent["RegOrgName"]=item["regOrgan"]--分支机构登记机关
				--print(childent["BrName"],childent["RegNO"],childent["RegOrgName"])
				table.insert(childents, childent)
			end
		end
	end
	return childents
end

function getPunishInfo(content)
	local punishInfos={}
	local list=findListHtml("table#penTab tr",content)
	local len=table.getn(list)
	if len>0 then
		for k,v in pairs(list) do
			if k>2 then
				local item={}
				item["PenDecNo"]="td:eq(1)"
				item["IllegActTypeName"]="td:eq(2)"
				item["PenResult"]="td:eq(3)"
				item["OrgName"]="td:eq(4)"
				item["PenDecIssDate"]="td:eq(5)"
				item=findMap(item,"<table>><tr>"..v.."</tr></table>")
				local punishInfo={}
				punishInfo["PenDecNo"]=item["PenDecNo"]--行政处罚号
				punishInfo["IllegActTypeName"]=item["IllegActTypeName"]--行政处罚类型名称
				punishInfo["PenResult"]=item["PenResult"]--处罚结果
				punishInfo["OrgName"]=item["OrgName"]--机构
				punishInfo["PenDecIssDate"]=item["PenDecIssDate"]--日期
				--print(punishInfo["PenDecNo"],punishInfo["IllegActTypeName"],punishInfo["PenResult"],punishInfo["OrgName"],punishInfo["PenDecIssDate"])
				table.insert(punishInfos, punishInfo)
			end
		end
	end
	return punishInfos
end


function getExcDirec(content)
	local excDirecs={}
	local list=findListHtml("table#excpTab tr",content)
	local len=table.getn(list)
	if len>0 then
		for k,v in pairs(list) do
			if k>2  then
				local excDirec={}
				item={}
				item["DecOrg"]="td:eq(5)"
				item["SpeCause"]="td:eq(1)"
				item["AbnTime"]="td:eq(2)"
				item["OutSpeTim"]="td:eq(4)"
				item["OutSpeCause"]="td:eq(3)"
				
				item=findMap(item,"<table>><tr>"..v.."</tr></table>")
				excDirec["DecOrg"]=com.trim(item["DecOrg"])
				excDirec["SpeCause"]=com.trim(item["SpeCause"])	
				excDirec["AbnTime"]=com.trim(item["AbnTime"])
				excDirec["OutSpeTim"]=com.trim(item["OutSpeTim"])
				excDirec["OutSpeCause"]=com.trim(item["OutSpeCause"])
				--print(excDirec["DecOrg"],excDirec["SpeCause"],excDirec["AbnTime"],excDirec["OutSpeTim"],excDirec["OutSpeCause"])
				table.insert(excDirecs, excDirec)
			end
		end
	end
	return excDirecs
end

function getNbList(content,cookies,head)
	local str=findOneText("div#leftTabs ul li:eq(1):attr(onclick)",content)
	str=string.gsub(str,"togo%(","")
	str=string.gsub(str,"%)","")
	local tmp=com.split(str,",")
	local pripid=strDel(tmp[2])
	local regno=strDel(tmp[3])
	local entcate=strDel(tmp[4])
	
	--print(pripid,regno,entcate)
	local param={
		["pripid"]=pripid,
		["regno"]=regno,
		["entcate"]=entcate
	}
	local _content,_=downloadAdv("http://xygs.gsaic.gov.cn/gsxygs/pub!viewE.do","post",param,head,cookies)
	--print(_content)
	local list=findListHtml("div#qiyenianbao table.detailsList:eq(0) tr",_content)
	--print("list length:",table.getn(list))
	local nbinfos={}
	if table.getn(list)>0 then
		for k,v in pairs(list) do
			if k>2 then
				local item={}
				item["href"]="td:eq(1) a:eq(0):attr(onclick)"
				item["nd"]="td:eq(1) a:eq(0)"
				item=findMap(item,"<table>><tr>"..v.."</tr></table>")
				--print(item["href"])
				item["href"]=string.gsub(item["href"],"window.open%(","")
				item["href"]=string.gsub(item["href"],"%)","")
				item["href"]=strDel(item["href"])
				local __content,_=downloadAdv("http://xygs.gsaic.gov.cn"..item["href"],"get",{},head,cookies)
				local nbinfo=getExYear(__content)
				nbinfo["ancheyear"]=item["nd"]
				table.insert(nbinfos, 1, nbinfo)
			end
			
		end
	end
	return nbinfos
end



function getExYear(content)
	--print(content)
	local nb={}
	--年报基本信息
	local th=findListText("div#qufenkuang table.detailsList:eq(0) tr th",content)
	local td=findListText("div#qufenkuang table.detailsList:eq(0) tr td",content)
	local tab={}
	for k,v in pairs(th) do
		if k>2 then
			local tdv=com.trim(td[k-2])
			tab[com.trim(v)]=tdv
			--print(com.trim(v),tab[com.trim(v)])
		end
	end
	local nbbase=ecps.reversalFormat(tab,ecps.baseNbFm,ecps.baseNbMap)
	nb["base"]=nbbase
	
	
	--股东及出资信息
	local gdList=findListHtml("table#invTab tr",content)
	local gdLen=table.getn(gdList)
	local gdczs={}
	if gdLen>0 then
		for k,v in pairs(gdList) do
			if k>2 then
				--print(v)
				local item={}
				item["inv"]="td:eq(0)"
				item["acConAm"]="td:eq(4)" 
				item["realConDate"]="td:eq(5)"
				item["realConForm"]="td:eq(6)"
				item["subConAm"]="td:eq(1)"
				item["subConAmForm"]="td:eq(3)"
				item["subConAmDate"]="td:eq(2)"
				item=findMap(item,"<table>><tr>"..v.."</tr></table>")
				local gdcz={}
				gdcz["inv"]=com.trim(item["inv"])--股东
				gdcz["acConAm"]=com.trim(item["acConAm"]) --实缴出资额
				gdcz["realConDate"]=com.trim(item["realConDate"])--实缴出资时间
				gdcz["realConForm"]=com.trim(item["realConForm"])--实缴出资方式
				gdcz["subConAm"]=com.trim(item["subConAm"])--认缴出资额
				gdcz["subConAmForm"]=com.trim(item["subConAmForm"])--认缴出资方式
				gdcz["subConAmDate"]=com.trim(item["subConAmDate"])--认缴出资时间
				table.insert(gdczs,gdcz)
				--print(gdcz["inv"],gdcz["subConAm"],gdcz["subConAmDate"],gdcz["subConAmForm"],gdcz["acConAm"],gdcz["realConDate"],gdcz["realConForm"])
			end
		end
	end
	nb["invs"]=gdczs
	
	
	--对外投资信息
	local tzList=findListHtml("table#invoutTab tr",content)
	local tzLen=table.getn(tzList)
	local tzs={}
	if tzLen>0 then
		for k,v in pairs(tzList) do
			if k>2 then
				local item={}
				item["name"]="td:eq(0)"
				item["regno"]="td:eq(1)" 
				item=findMap(item,"<table>><tr>"..v.."</tr></table>")
				local tz={}
				tz["name"]=com.trim(item["name"])--名称
				tz["regno"]=com.trim(item["regno"]) --注册号
				table.insert(tzs,tz)
				--print(tz["name"],tz["regno"])
			end
		end
	end
	nb["investment"]=tzs
	
	--企业资产状况信息
	local qyzc={}
	local th=findListText("table.detailsList:eq(4) tr th",content)
	local td=findListText("table.detailsList:eq(4) tr td",content)
	for k,v in pairs(th) do
		if k>1 then
			--print(v)
			qyzc[com.trim(v)]=com.trim(td[k-1])
			--print(com.trim(v),com.trim(td[k-1]))
		end
	end
	nb["assetstatus"]=qyzc
	
	
	--对外提供保证担保信息
	local dbList=findListHtml("table#guaTab tr",content)
	local dbLen=table.getn(dbList)
	local dwdbs={}
	for k,v in pairs(dbList) do
		if k>2 and k<dbLen then
			--print(v)
			local dwdb={}
			item={}
			item["more"]="td:eq(0)"--债权人
			item["mortgagor"]="td:eq(1)" --债务人
			item["priclaseckindvalue"]="td:eq(2)"--主债权种类
			item["priclasecam"]="td:eq(3)"--主债权数额
			item["pefperformandto"]="td:eq(4)"--履行债务的期限
			item["guaranperiodvalue"]="td:eq(5)"--保证的期间
			item["gatypevalue"]="td:eq(6)"--保证的方式
			--item["ragevalue"]="td:eq(7)"--保证担保的范围
			item=findMap(item,"<table>><tr>"..v.."</tr></table>")
			dwdb["more"]=com.trim(item["more"]) 
			dwdb["mortgagor"]=com.trim(item["mortgagor"])
			dwdb["priclaseckindvalue"]=com.trim(item["priclaseckindvalue"]) 
			dwdb["priclasecam"]=com.trim(item["priclasecam"])
			dwdb["pefperformandto"]=com.trim(item["pefperformandto"]) 
			dwdb["guaranperiodvalue"]=com.trim(item["guaranperiodvalue"])
			dwdb["gatypevalue"]=com.trim(item["gatypevalue"]) 
			--dwdb["ragevalue"]=com.trim(item["ragevalue"])  
			table.insert(dwdbs,dwdb)
		end
	end
	nb["guarantees"]=dwdbs
	
	
	--股权变更信息
	local bgList=findListHtml("table#transTab tr",content)
	local bgLen=table.getn(bgList)
	local bgs={}
	if bgLen>0 then
		for k,v in pairs(bgList) do
			if k>2 then
				local bg={}
				item={}
				item["inv"]="td:eq(0)"
				item["transbmpr"]="td:eq(1)" 
				item["transampr"]="td:eq(2)"
				item["altdate"]="td:eq(3)"
				item=findMap(item,"<table>><tr>"..v.."</tr></table>")
				bg["inv"]=item["inv"] --股东
				bg["transbmpr"]=item["transbmpr"] --变更前股权比例
				bg["transampr"]=item["transampr"] --变更后股权比例				
				bg["altdate"]=item["altdate"] --股权变更日期
				--print(bg["inv"],bg["transbmpr"],bg["transampr"],bg["altdate"])
				table.insert(bgs, bg)
			end
		end
	end
	nb["equitychange"]=bgs
	
	return nb
end







function strDel(str)
	str=string.gsub(str,"\'","")
	return str
end



function checkData(title,entInfo)
	local entName=entInfo["EntName"]
	local regNo=entInfo["RegNo"]
	if entName=="" or entName==nil or title~=entName then
		print(title.."  甘肃数据下载出错或者不完整重新下载")
		return false
	end
	if regNo=="" or regNo==nil then
		print(title.."  甘肃数据下载出错或者不完整重新下载")
		return false
	end
	--print(entInfo["EntName"].."数据完整")
	return true
end