parent
64a206f347
commit
c143ca8a02
@ -0,0 +1,47 @@
|
||||
from tkinter import*
|
||||
|
||||
user_login ={'aaa':'123456', 'bbb':'888888', 'ccc':'333333', }
|
||||
|
||||
#定义登录次数
|
||||
count =0
|
||||
def login():
|
||||
global count
|
||||
username =entry_username.get ()
|
||||
if username not in user_login:
|
||||
label_message.config(text='账号错误!')
|
||||
else:
|
||||
password =entry_password.get ()
|
||||
if (password ==user_login[username]):
|
||||
label_message.config(text='登录成功!')
|
||||
open_new_window()
|
||||
else:
|
||||
label_message.config(text='密码错误!还可以尝试{}次'.format (2 -coum))
|
||||
count = count +1
|
||||
if count ==3:
|
||||
label_message.config(text='登录失败!')
|
||||
btn_login.config(state="disabled")
|
||||
def open_new_window():
|
||||
# 创建一个新窗口
|
||||
new_window = Toplevel(window)
|
||||
new_window.title("登录成功")
|
||||
new_window.geometry("300x200")
|
||||
Label(new_window, text="欢迎进入新页面!").pack()
|
||||
window =Tk()
|
||||
window.title("用户登录")
|
||||
window.geometry("300x200")
|
||||
#创建标签和输入框
|
||||
label_username=Label(window, text="账号:")
|
||||
label_username.pack()
|
||||
entry_username =Entry (window)
|
||||
entry_username.pack ()
|
||||
label_password=Label (window, text="密码:")
|
||||
label_password.pack ()
|
||||
entry_password = Entry(window, show='*')
|
||||
entry_password.pack()
|
||||
#创建登录按钮和消息提示标签
|
||||
btn_login =Button (window, text="登录", command=login)
|
||||
btn_login.pack()
|
||||
label_message = Label (window, text ="")
|
||||
label_message.pack()
|
||||
#运行主循环
|
||||
window.mainloop ()
|
@ -0,0 +1,49 @@
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.common.keys import Keys
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from time import sleep
|
||||
|
||||
def create_driver():
|
||||
""" 创建并配置 WebDriver 实例 """
|
||||
options = webdriver.EdgeOptions()
|
||||
#options.add_argument("--headless") # 无界面模式
|
||||
options.add_argument("--start-maximized") # 最大化窗口
|
||||
options.add_argument("--disable-notifications") # 禁用通知
|
||||
options.add_argument("user-data-dir=C:/Users/JJM/AppData/Local/Microsoft/Edge/User Data/Default")
|
||||
options= webdriver.EdgeOptions()
|
||||
options.add_experimental_option("detach", True)
|
||||
driver = webdriver.Edge(options=options)
|
||||
return driver
|
||||
|
||||
def login():
|
||||
driver = create_driver()
|
||||
try:
|
||||
driver.get("https://contest.cdec.org.cn/#/signin")
|
||||
# 使用显式等待确保元素可交互
|
||||
sleep(2)
|
||||
|
||||
driver.find_element(By.XPATH,'//*[@id="app"]/div/div[3]/div/form/div[1]/div/div/div/input').send_keys('15367278097',Keys.ENTER)
|
||||
sleep(2)
|
||||
|
||||
|
||||
driver.find_element(By.XPATH,'//*[@id="app"]/div/div[3]/div/form/div[2]/div/div/div/input').send_keys('123456',Keys.ENTER)
|
||||
sleep(2)
|
||||
driver.find_element(By.XPATH,'//*[@id="app"]/div/div[3]/div/form/div[3]/div[1]/div/div/button').click()
|
||||
sleep(2) # 简单延时等待操作完成
|
||||
finally:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
with ThreadPoolExecutor(max_workers=10) as executor: # 同时启动10个线程
|
||||
futures = [executor.submit(login) for _ in range(10)]
|
||||
for future in futures:
|
||||
future.result()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Binary file not shown.
Binary file not shown.
@ -0,0 +1,31 @@
|
||||
from typing import List
|
||||
|
||||
import mysql
|
||||
import mysql.connector
|
||||
import csv
|
||||
def hello():
|
||||
db_config = {
|
||||
'host': 'localhost',
|
||||
'user': 'root',
|
||||
'password': '12345678M',
|
||||
'database': 'pinglun',
|
||||
}
|
||||
cnx = mysql.connector.connect(**db_config)
|
||||
cursor = cnx.cursor()
|
||||
# 读取CSV
|
||||
with open('评论.csv', mode='r', encoding='utf-8') as file:
|
||||
reader = csv.reader(file)
|
||||
headers = next(reader, None)
|
||||
if headers is not None: # 过表头
|
||||
for row in reader:
|
||||
sql = "INSERT IGNORE INTO pinglunxinxi(nicheng,pinglun,chanpingxinxi) VALUES (%s, %s, %s)"
|
||||
cursor.execute(sql, (row[0], row[1], row[2])) #设csv与数据库对应
|
||||
try:
|
||||
cnx.commit()
|
||||
print("数据导入成功!")
|
||||
except mysql.connector.Error as err:
|
||||
print(f"数据导入失败: {err}")
|
||||
finally:
|
||||
cursor.close()
|
||||
cnx.close()
|
||||
hello()
|
@ -0,0 +1,33 @@
|
||||
from typing import List
|
||||
|
||||
import mysql
|
||||
import mysql.connector
|
||||
import csv
|
||||
def hello():
|
||||
import quchong
|
||||
qc()
|
||||
db_config = {
|
||||
'host': 'localhost',
|
||||
'user': 'root',
|
||||
'password': '12345678M',
|
||||
'database': 'pinglun',
|
||||
}
|
||||
cnx = mysql.connector.connect(**db_config)
|
||||
cursor = cnx.cursor()
|
||||
# 读取CSV
|
||||
with open('抖音评论.csv', mode='r', encoding='utf-8') as file:
|
||||
reader = csv.reader(file)
|
||||
headers = next(reader, None)
|
||||
if headers is not None: # 过表头
|
||||
for row in reader:
|
||||
sql = "INSERT IGNORE INTO douyinpinglunxinxi(nicheng,zhanghao,pinglun) VALUES (%s, %s,%s)"
|
||||
cursor.execute(sql, (row[0], row[1],row[2])) #设csv与数据库对应
|
||||
try:
|
||||
cnx.commit()
|
||||
print("数据导入成功!")
|
||||
except mysql.connector.Error as err:
|
||||
print(f"数据导入失败: {err}")
|
||||
finally:
|
||||
cursor.close()
|
||||
cnx.close()
|
||||
hello()
|
@ -0,0 +1,10 @@
|
||||
import pandas as pd
|
||||
def qc():
|
||||
# 加载CSV文件
|
||||
data = pd.read_csv('抖音评论.csv')
|
||||
|
||||
# 删除重复行
|
||||
data_cleaned = data.drop_duplicates()
|
||||
|
||||
# 保存清理后的数据到新文件
|
||||
data_cleaned.to_csv('抖音评论.csv', index=False)
|
@ -0,0 +1,46 @@
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.common.by import By
|
||||
|
||||
from selenium.webdriver.common.keys import Keys
|
||||
from time import sleep
|
||||
from selenium.webdriver.edge.service import Service
|
||||
from selenium.webdriver.edge.options import Options
|
||||
|
||||
|
||||
options = webdriver.EdgeOptions()
|
||||
options.add_argument("--start-maximized") # 最大化窗口
|
||||
options.add_argument("--disable-notifications") # 禁用通知
|
||||
options.headless = True
|
||||
options.add_argument("user-data-dir=C:/Users/JJM/AppData/Local/Microsoft/Edge/User Data/Default") # 使用本地用户数据目录
|
||||
options= webdriver.EdgeOptions()
|
||||
options.add_experimental_option("detach", True)
|
||||
|
||||
driver_edge = webdriver.Edge(options=options)
|
||||
|
||||
my_url = "https://www.douyin.com/"
|
||||
|
||||
driver_edge.get(my_url)
|
||||
sleep(11)
|
||||
|
||||
x=driver_edge.find_element(By.XPATH,'//*[@id="login-pannel"]/div[2]')
|
||||
x.click()
|
||||
sleep(10)
|
||||
# 模拟点击
|
||||
|
||||
search_box = driver_edge.find_element(By.XPATH,'//*[@id="douyin-header"]/div[1]/header/div/div/div[1]/div/div[2]/div/div/input').send_keys('zy2752629612',Keys.ENTER)
|
||||
|
||||
|
||||
sleep(15)
|
||||
|
||||
s=driver_edge.find_element(By.XPATH,'//*[@id="search-content-area"]/div/div[1]/div[2]/div[1]/ul/li/div/div/div/div/div/a')
|
||||
s.click()
|
||||
sleep(5)#/html/body/div[2]/div/div[2]/div[2]/div/div[1]/div[2]/div[1]/ul/li/div/div/div/div/div/a//*[@id="search-content-area"]/div/div[1]/div[2]/div[1]/ul/li/div/div/div/div/div/a
|
||||
h=driver_edge.find_element(By.XPATH,'//*[@id="douyin-right-container"]/div[2]/div/div/div[2]/div[3]/div[3]/div[1]/button[2]')
|
||||
h.click()
|
||||
# 获取cookie
|
||||
cookies = driver_edge.get_cookies()
|
||||
for cookie in cookies:
|
||||
print(cookie)
|
||||
|
||||
# 关闭浏览器
|
||||
driver_edge.quit()
|
Loading…
Reference in new issue