forked from Guovin/iptv-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
46 lines (42 loc) · 1.11 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from driver.setup import setup_driver
from utils.retry import (
retry_func,
locate_element_with_retry,
find_clickable_element_with_retry,
)
from time import sleep
import re
from bs4 import BeautifulSoup
from selenium.webdriver.common.by import By
def get_soup_driver(url):
"""
Get the soup by driver
"""
driver = setup_driver()
retry_func(lambda: driver.get(url), name=url)
sleep(1)
source = re.sub(
r"<!--.*?-->",
"",
driver.page_source,
flags=re.DOTALL,
)
soup = BeautifulSoup(source, "html.parser")
driver.close()
driver.quit()
return soup
def search_submit(driver, name):
"""
Input key word and submit with driver
"""
search_box = locate_element_with_retry(driver, (By.XPATH, '//input[@type="text"]'))
if not search_box:
return
search_box.clear()
search_box.send_keys(name)
submit_button = find_clickable_element_with_retry(
driver, (By.XPATH, '//input[@type="submit"]')
)
if not submit_button:
return
driver.execute_script("arguments[0].click();", submit_button)