python网页自动化脚本 python脚本的自动化

11/28 04:16:47 来源网站:辅助卡盟网

python网页自动化脚本 python脚本的自动化

嗨,stackoverflow社区,我想知道如何自动生成我的EPEX masterscript.py。我读到,我必须将扩展名py更改为pyw(在windows10系统上)。然后我想告诉我的脚本python网页自动化脚本,它应该在函数"datetime.date"的帮助下获取实际日期,给我属性:年、月和日。之后,它应该接管日、年、月python网页自动化脚本辅助论坛,而不是手动更改日、年和月。这个脚本现在是这样的,它将来自internetpage (beautifulsoup)的一些数据保存在PostgreSQL数据库中,但它是在手动执行下面的代码之后完成的。其主要思想是,在后台运行EPEX masterscript.py(计算机应该自动执行),并且该脚本每天在10a.m和下午6点删除两次。

你能帮我一些想法或解决方案吗???

这是我的代码(EPEX masterscript.py)):

from bs4 import BeautifulSoup 
import requests 
import datetime
from datetime import date
import psycopg2
#day= 31
#year= 2022
#month= 8
datetime_object = datetime.datetime.now()
kw= datetime.date(datetime_object.year, datetime_object.month, datetime_object.day).isocalendar()[1]
link= date(datetime_object.year, datetime_object.month, datetime_object.day).isoformat()
#print('Heute ist der:',"\n", datetime_object, "\n")
headers= {'user-agent':'Mozilla/5.0'}
page_response1 = requests.get('https://www.epexspot.com/en/market-data?market_area=DE&delivery_date='+link+'&underlying_year=&modality=Continuous&sub_modality=&product=60&data_mode=table&period=', headers=headers)
EPEX = BeautifulSoup(page_response1.content, 'html.parser') 
conn = psycopg2.connect("dbname='Demonstratoren Statische Daten' user='postgres' password='NRL-HAW-2022' host='localhost'")
cur = conn.cursor()
query = ' SELECT * from "EPEX_2022" ORDER by id DESC LIMIT 1'
cur.execute(query) 
rows = cur.fetchall()
fr = (rows[0])[0]
fr +=1
Verkaufstag= EPEX.find_all("h2")
list=[]
for i in Verkaufstag:
        list.append(i.text)
#index = list[1].index('22 June 2022')
#print("Verkaufstag:",list[1][208:220])
   
f0= EPEX.find ("tr", {"class":"child-0"}).text
f1= EPEX.find ("tr", {"class":"child-1 impair"}).text
f2= EPEX.find ("tr", {"class":"child-2"}).text
f3= EPEX.find ("tr", {"class":"child-3 impair"}).text
f4= EPEX.find ("tr", {"class":"child-4"}).text
f5= EPEX.find ("tr", {"class":"child-5 impair"}).text
f6= EPEX.find ("tr", {"class":"child-6"}).text
f7= EPEX.find ("tr", {"class":"child-7 impair"}).text
f8= EPEX.find ("tr", {"class":"child-8"}).text
f9= EPEX.find ("tr", {"class":"child-9 impair"}).text
f10= EPEX.find ("tr", {"class":"child-10"}).text
f11= EPEX.find ("tr", {"class":"child-11 impair"}).text
f12= EPEX.find ("tr", {"class":"child-12"}).text
f13= EPEX.find ("tr", {"class":"child-13 impair"}).text
f14= EPEX.find ("tr", {"class":"child-14"}).text
f15= EPEX.find ("tr", {"class":"child-15 impair"}).text
f16= EPEX.find ("tr", {"class":"child-16"}).text
f17= EPEX.find ("tr", {"class":"child-17 impair"}).text
f18= EPEX.find ("tr", {"class":"child-18"}).text
f19= EPEX.find ("tr", {"class":"child-19 impair"}).text
f20= EPEX.find ("tr", {"class":"child-20"}).text
f21= EPEX.find ("tr", {"class":"child-21 impair"}).text
f22= EPEX.find ("tr", {"class":"child-22"}).text
f23= EPEX.find ("tr", {"class":"child-23 impair"}).text
conn = None
conn = psycopg2.connect(database="Demonstratoren Statische Daten", user="postgres", password="NRL-HAW-2022", host="localhost")
curs = conn.cursor()
a=list[1][208:]
g0=f0.split()
b=g0[3]
g1=f1.split()
c=g1[3]
g2=f2.split()
d=g2[3]
g3=f3.split()
e=g3[3]
g4=f4.split()
f=g4[3]
g5=f5.split()
g=g5[3]
g6=f6.split()
h=g6[3]
g7=f7.split()
i=g7[3]
g8=f8.split()
j=g8[3]
g9=f9.split()
k=g9[3]
g10=f10.split()
l=g10[3]
g11=f11.split()
m=g11[3]
g12=f12.split()
n=g12[3]
g13=f13.split()
o=g13[3]
g14=f14.split()
p=g14[3]
g15=f15.split()
q=g15[3]
g16=f16.split()
r=g16[3]
g17=f17.split()
s=g17[3]
g18=f18.split()
t=g18[3]
g19=f19.split()
u=g19[3]
g20=f20.split()
v=g20[3]
g21=f21.split()
w=g21[3]
g22=f22.split()
x=g22[3]
g23=f23.split()
y=g23[3]
SQL = """INSERT INTO "EPEX_2022" (id, handelstag, zeitraum_0_bis_1uhr, zeitraum_1_bis_2uhr, zeitraum_2_bis_3uhr, zeitraum_3_bis_4uhr, zeitraum_4_bis_5uhr, zeitraum_5_bis_6uhr, zeitraum_6_bis_7uhr, zeitraum_7_bis_8uhr, zeitraum_8_bis_9uhr, zeitraum_9_bis_10uhr, zeitraum_10_bis_11uhr, zeitraum_11_bis_12uhr, zeitraum_12_bis_13uhr, zeitraum_13_bis_14uhr, zeitraum_14_bis_15uhr, zeitraum_15_bis_16uhr, zeitraum_16_bis_17uhr, zeitraum_17_bis_18uhr, zeitraum_18_bis_19uhr, zeitraum_19_bis_20uhr, zeitraum_20_bis_21uhr, zeitraum_21_bis_22uhr, zeitraum_22_bis_23uhr, zeitraum_23_bis_24uhr, zeitraum_kw) 
VALUES ( %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"""
data = (fr, str(a), b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, kw)
curs.execute(SQL, data)
conn.commit()
# Finden von Duplikaten und sie Anzeigen lassen print(fetch)
conn = None
conn = psycopg2.connect(database="Demonstratoren Statische Daten", user="postgres", password="NRL-HAW-2022", host="localhost")
query1 = """ SELECT DISTINCT  * FROM "EPEX_2022" 
where handelstag in ( select handelstag from (
select handelstag, count(*)
from "EPEX_2022"
group by handelstag
HAVING count(*) > 1) as total
Order by id);"""
    
cur.execute(query1) 
fetch = cur.fetchall()
#print(fetch)
# Löschen von Duplikaten und erhalten der ersten id (ursprünglich ersten Eintrags)
conn = None
conn = psycopg2.connect(database="Demonstratoren Statische Daten", user="postgres", password="NRL-HAW-2022", host="localhost")
cur = conn.cursor()
query2= """ DELETE FROM "EPEX_2022"
WHERE ID IN 
(SELECT ID
FROM (SELECT id, ROW_NUMBER() OVER (partition BY handelstag ORDER BY ID) AS RowNumber
     FROM "EPEX_2022") AS T
WHERE T.RowNumber > 1); """
cur.execute(query2)
conn.commit()
conn = None

来源:【九爱网址导航www.fuzhukm.com】 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

    暂无相关资讯
python网页自动化脚本 python脚本的自动化