|
|
|
@ -8,66 +8,88 @@ from selenium.webdriver.edge.options import Options
|
|
|
|
|
from selenium.webdriver.support.ui import WebDriverWait
|
|
|
|
|
from selenium.common.exceptions import TimeoutException
|
|
|
|
|
options = webdriver.EdgeOptions()
|
|
|
|
|
#options.add_argument("--headless")
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
cookies = driver_edge.get_cookies()
|
|
|
|
|
for cookie in cookies:
|
|
|
|
|
print(cookie)
|
|
|
|
|
my_url = "https://www.douyin.com/"
|
|
|
|
|
|
|
|
|
|
driver_edge.get(my_url)
|
|
|
|
|
sleep(70)
|
|
|
|
|
sleep(5)
|
|
|
|
|
|
|
|
|
|
# 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)
|
|
|
|
|
# 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)
|
|
|
|
|
|
|
|
|
|
search_box = driver_edge.find_element(By.XPATH,'//input[@class="st2xnJtZ YIde9aUh"]')
|
|
|
|
|
|
|
|
|
|
sleep(20)
|
|
|
|
|
driver_edge.execute_script("window.scrollTo(0, document.body.scrollHeight);")
|
|
|
|
|
sleep(10) # 等待滚动效果
|
|
|
|
|
#f=driver_edge.find_element(By.CLASS_NAME,'B3AsdZT9 BMJLsW6X').click()
|
|
|
|
|
elements = driver_edge.find_elements(By.XPATH, "//*")
|
|
|
|
|
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')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 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)
|
|
|
|
|
# 检查每个元素是否可见
|
|
|
|
|
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)
|
|
|
|
|
# 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
# 等待元素可见,超时设置为5秒
|
|
|
|
|
WebDriverWait(driver_edge, 5).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(10) # 等待滚动效果
|
|
|
|
|
|
|
|
|
|
# 再次检查元素是否可见
|
|
|
|
|
if element.is_displayed():
|
|
|
|
|
print("元素现在可见")
|
|
|
|
|
else:
|
|
|
|
|
print("元素仍不可见")
|
|
|
|
|
# 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("元素仍不可见")
|
|
|
|
|
sleep(10)
|
|
|
|
|
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]')
|
|
|
|
|
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]')
|
|
|
|
|
h.click()
|
|
|
|
|
# 获取cookie
|
|
|
|
|
cookies = driver_edge.get_cookies()
|
|
|
|
|
for cookie in cookies:
|
|
|
|
|
print(cookie)
|
|
|
|
|
b=driver_edge.find_element(By.XPATH,'//div[@class="c8uBfaOs"]/div[@class="public-DraftEditorPlaceholder-inner"]')
|
|
|
|
|
b.send_keys('zy2752629612',Keys.ENTER)
|
|
|
|
|
|
|
|
|
|
# 关闭浏览器
|
|
|
|
|
driver_edge.quit()
|
|
|
|
|
# # 关闭浏览器
|
|
|
|
|
# driver_edge.quit()
|