from selenium import webdriver
import time
from selenium.webdriver.common.by import By
import os
import pymysql
import decimal
import sys
import openpyxl
import uuid
def down(date):
options = webdriver.ChromeOptions()
options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
browser = webdriver.Chrome(options=options)
browser.get(f"https://www.iwencai.com/unifiedwap/result?w={date}%20%E7%AB%9E%E4%BB%B7%E6%B6%A8%E5%B9%85%20%E6%B5%81%E5%8A%A8%E5%B8%82%E5%80%BC%20%E6%A6%82%E5%BF%B5%20{date}%E9%BE%99%E5%A4%B4%20%E4%BA%8C%E7%BA%A7%E8%A1%8C%E4%B8%9A&querytype=stock")
time.sleep(2)
button = browser.find_element(By.CLASS_NAME,'table-export');
button.click();
browser.quit();
pass
def objToStr(value):
if value is None:
return ""
else:
return str(value)
def strToDecimal(str):
str = objToStr(str)
if str == "":
str = "0"
return decimal.Decimal(str)
def getDate():
return time.strftime('%Y-%m-%d', time.localtime(time.time()));
def getConn1():
return pymysql.connect(host="127.0.0.1",port=3306,user="root",passwd="123456",db="wc_data" )
def importAll(date):
path='D:\\Users\Administrator\\下载'
for file_name in os.listdir(path):
if "竞价涨幅" in file_name:
print(file_name)
importFile(path + "\\" + file_name,date);
time.sleep(3);
os.remove(path + "\\" + file_name);
def importFile(filename,date):
conn1 = getConn1();
cursor1 = conn1.cursor();
inwb = openpyxl.load_workbook(filename);
sheetsname = inwb.sheetnames;
ws = inwb[sheetsname[0]];
rows = ws.max_row -1;
cols = ws.max_column;
print(rows);
print(cols);
i = 2
value = "";
while i <= rows:
code = ws.cell(i,1).value;
name = ws.cell(i,2).value;
zf = ws.cell(i,5).value;
type_name = ws.cell(i,9).value;
notions = ws.cell(i,7).value;
sz = ws.cell(i,18).value;
amount = ws.cell(i,15).value;
if zf == "--":
zf = "0";
if sz == "--":
sz = "0";
if amount == "--":
amount = "0";
value += f"('{date}','{code}', '{name}','{zf}','{type_name}','{notions}','{sz}','{amount}'),";
i = i + 1;
pass
value = value[:-1];
sql = f"delete from k_data_jj ";
cursor1.execute(sql)
conn1.commit()
if value != "":
sql = f'INSERT into k_data_jj(date,code,name,zf,type,notions,sz,amount) VALUES {value}';
count = cursor1.execute(sql)
conn1.commit()
inwb.close();
def job():
date = getDate();
#down(date);
#time.sleep(20);
importAll(date);
job();
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
query_wc_data.zip (2个子文件)
query_wc_jhjj.py 3KB
k_data_jj.sql 914B
共 2 条
- 1
资源评论
我是唐赢
- 粉丝: 593
- 资源: 21
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功