From 8220ef6ee21074140cce04390c3d053db00dd8af Mon Sep 17 00:00:00 2001 From: "guorong.zheng" <360996299@qq.com> Date: Thu, 25 Apr 2024 10:41:05 +0800 Subject: [PATCH 1/3] feat:simulate click --- main.py | 23 ++++++++++++++--------- utils.py | 6 +++--- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index 1935e02dd0a..ced038d0b94 100644 --- a/main.py +++ b/main.py @@ -63,9 +63,7 @@ def __init__(self): async def visitPage(self, channelItems): total_channels = sum(len(channelObj) for _, channelObj in channelItems.items()) pbar = tqdm(total=total_channels) - pageObj = await useAccessibleUrl() - pageUrl = pageObj["url"] - pageName = pageObj["name"] + pageUrl = await useAccessibleUrl() for cate, channelObj in channelItems.items(): channelUrls = {} channelObjKeys = channelObj.keys() @@ -73,6 +71,14 @@ async def visitPage(self, channelItems): pbar.set_description( f"Processing {name}, {total_channels - pbar.n} channels remaining" ) + self.driver.get(pageUrl) + search_box = self.driver.find_element(By.XPATH, '//input[@type="text"]') + search_box.clear() + search_box.send_keys(name) + submit_button = self.driver.find_element( + By.XPATH, '//input[@type="submit"]' + ) + submit_button.click() isFavorite = name in config.favorite_list pageNum = ( config.favorite_page_num if isFavorite else config.default_page_num @@ -81,13 +87,11 @@ async def visitPage(self, channelItems): if pageUrl: for page in range(1, pageNum + 1): try: - page_url = f"{pageUrl}?page={page}&{pageName}={name}" - self.driver.get(page_url) - WebDriverWait(self.driver, 10).until( - EC.presence_of_element_located( - (By.CSS_SELECTOR, "div.result") + if page > 1: + page_link = self.driver.find_element( + By.XPATH, f'//a[contains(@href, "page={page}")]' ) - ) + page_link.click() soup = BeautifulSoup(self.driver.page_source, "html.parser") results = ( soup.find_all("div", class_="result") if soup else [] @@ -95,6 +99,7 @@ async def visitPage(self, channelItems): for result in results: try: url, date, resolution = getUrlInfo(result) + print(url, date, resolution) if ( url and checkUrlIPVType(url) diff --git a/utils.py b/utils.py index 7f45909013f..93dca74d779 100644 --- a/utils.py +++ b/utils.py @@ -268,8 +268,8 @@ async def useAccessibleUrl(): speed1 = await getSpeed(baseUrl1, 30) speed2 = await getSpeed(baseUrl2, 30) if speed1 == float("inf") and speed2 == float("inf"): - return {"url": None, "name": None} + return None if speed1 < speed2: - return {"url": baseUrl1, "name": "s"} + return baseUrl1 else: - return {"url": baseUrl2, "name": "tv"} + return baseUrl2 From 4a4af728d6dfc87cb3eef0017642f6cc005427ab Mon Sep 17 00:00:00 2001 From: "guorong.zheng" <360996299@qq.com> Date: Thu, 25 Apr 2024 11:07:27 +0800 Subject: [PATCH 2/3] chore:contains --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index ced038d0b94..0be266c1a11 100644 --- a/main.py +++ b/main.py @@ -89,7 +89,8 @@ async def visitPage(self, channelItems): try: if page > 1: page_link = self.driver.find_element( - By.XPATH, f'//a[contains(@href, "page={page}")]' + By.XPATH, + f'//a[contains(@href, "={page}") and contains(@href, "{name}")]', ) page_link.click() soup = BeautifulSoup(self.driver.page_source, "html.parser") @@ -99,7 +100,6 @@ async def visitPage(self, channelItems): for result in results: try: url, date, resolution = getUrlInfo(result) - print(url, date, resolution) if ( url and checkUrlIPVType(url) From 485a1abcbb08c8390a721313a3201a27535b8f6b Mon Sep 17 00:00:00 2001 From: "guorong.zheng" <360996299@qq.com> Date: Thu, 25 Apr 2024 15:41:25 +0800 Subject: [PATCH 3/3] release: v1.0.9 --- CHANGELOG.md | 6 ++++++ version.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0025af6112b..4128f2761a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # 更新日志(Changelog) +## v1.0.9 + +### 2024/4/25 + +- 改进接口获取方法,增强处理多种失效场景(Improve the method of obtaining the interface, enhance the handling of various failure scenarios) + ## v1.0.8 ### 2024/4/24 diff --git a/version.json b/version.json index bb2fbd5ad34..f8696f844c4 100644 --- a/version.json +++ b/version.json @@ -1,3 +1,3 @@ { - "version": "1.0.8" + "version": "1.0.9" } \ No newline at end of file