You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
3.4 KiB

6 months ago
from selenium import webdriver
from selenium.webdriver.common.by import By
6 months ago
from selenium.webdriver.support import expected_conditions as EC
6 months ago
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
6 months ago
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException
6 months ago
options = webdriver.EdgeOptions()
6 months ago
#options.add_argument("--headless")
6 months ago
options.add_argument("--start-maximized") # 最大化窗口
options.add_argument("--disable-notifications") # 禁用通知
6 months ago
6 months ago
options.add_argument("user-data-dir=C:/Users/JJM/AppData/Local/Microsoft/Edge/User Data/Default") # 使用本地用户数据目录
6 months ago
6 months ago
options.add_experimental_option("detach", True)
driver_edge = webdriver.Edge(options=options)
6 months ago
cookies = driver_edge.get_cookies()
for cookie in cookies:
print(cookie)
6 months ago
my_url = "https://www.douyin.com/"
driver_edge.get(my_url)
6 months ago
sleep(5)
6 months ago
6 months ago
# x=driver_edge.find_element(By.XPATH,'//*[@id="login-pannel"]/div[2]')
# x.click()
# sleep(10)
6 months ago
# 模拟点击
6 months ago
# 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)
6 months ago
6 months ago
search_box = driver_edge.find_element(By.XPATH,'//input[@class="st2xnJtZ YIde9aUh"]')
6 months ago
6 months ago
print(search_box)
search_box.send_keys('zy2752629612',Keys.ENTER)
sleep(5)
print('===========>111111111')
handles = driver_edge.window_handles #获取当前浏览器的所有窗口句柄
driver_edge.switch_to.window(handles[-1])
divm = driver_edge.find_element(By.XPATH,'//div[@class="G8LTciwG"]/a')
divm.click()
print('==============66666')
6 months ago
6 months ago
# sleep(10)
# driver_edge.execute_script("window.scrollTo(0, document.body.scrollHeight);")
# sleep(1) # 等待滚动效果
#f=driver_edge.find_element(By.CLASS_NAME,'B3AsdZT9 BMJLsW6X').click()
# elements = driver_edge.find_elements(By.XPATH, "//*")
# print(elements)
6 months ago
# 检查每个元素是否可见
6 months ago
# for element in elements:
# if element.is_displayed():
# print(f"元素 {element.tag_name} 可见")
# else:
# print(f"元素 {element.tag_name} 不可见")
# driver_edge.execute_script("arguments[0].style.display = 'block'; arguments[0].style.visibility = 'visible';", element)
6 months ago
6 months ago
# try:
# # 等待元素可见超时设置为5秒
# WebDriverWait(driver_edge, 1).until(
# EC.visibility_of(element)
# )
# print(f"元素 {element.tag_name} 现在可见")
# except TimeoutException:
# print(f"元素 {element.tag_name} 仍然不可见")
# driver_edge.execute_script("arguments[0].scrollIntoView(true);", element)
# sleep(1) # 等待滚动效果
# # 再次检查元素是否可见
# if element.is_displayed():
# print("元素现在可见")
# else:
# print("元素仍不可见")
6 months ago
sleep(10)
6 months ago
handles = driver_edge.window_handles #获取当前浏览器的所有窗口句柄
driver_edge.switch_to.window(handles[-1])
print('==============66666')
h=driver_edge.find_element(By.XPATH,'//div[@class="hLIm2dFu"]/button[2]')
6 months ago
h.click()
6 months ago
b=driver_edge.find_element(By.XPATH,'//div[@class="c8uBfaOs"]/div[@class="public-DraftEditorPlaceholder-inner"]')
b.send_keys('zy2752629612',Keys.ENTER)
6 months ago
6 months ago
# # 关闭浏览器
# driver_edge.quit()