|
@@ -244,16 +244,18 @@ class ShipinhaoSearch:
|
|
|
webviews = driver.contexts
|
|
|
Common.logger(log_type, crawler).info(f"webviews:{webviews}")
|
|
|
for webview in webviews:
|
|
|
+ if webview == 'NATIVE_APP':
|
|
|
+ continue
|
|
|
driver.switch_to.context(webview)
|
|
|
time.sleep(1)
|
|
|
windowHandles = driver.window_handles
|
|
|
for handle in windowHandles:
|
|
|
driver.switch_to.window(handle)
|
|
|
- try:
|
|
|
- driver.find_element(By.XPATH, '//div[@class="unit"]')
|
|
|
+ time.sleep(1)
|
|
|
+ if len(driver.find_elements(By.XPATH, '//div[@class="unit"]')) != 0:
|
|
|
Common.logger(log_type, crawler).info('切换 webview 成功')
|
|
|
return "成功"
|
|
|
- except Exception:
|
|
|
+ else:
|
|
|
Common.logger(log_type, crawler).info("切换 webview 失败")
|
|
|
|
|
|
@classmethod
|
|
@@ -547,13 +549,16 @@ class ShipinhaoSearch:
|
|
|
driver.implicitly_wait(10)
|
|
|
Common.logger(log_type, crawler).info("点击搜索框")
|
|
|
Common.logging(log_type, crawler, env, "点击搜索框")
|
|
|
- driver.find_element(By.ID, 'com.tencent.mm:id/j5t').click()
|
|
|
+ # driver.find_element(By.ID, 'com.tencent.mm:id/j5t').click() # 微信8.0.30版本
|
|
|
+ driver.find_element(By.ID, 'com.tencent.mm:id/he6').click() # 微信8.0.16版本
|
|
|
time.sleep(0.5)
|
|
|
- driver.find_element(By.ID, 'com.tencent.mm:id/cd7').clear().send_keys(word)
|
|
|
+ # driver.find_element(By.ID, 'com.tencent.mm:id/cd7').clear().send_keys(word) # 微信8.0.30版本
|
|
|
+ driver.find_element(By.ID, 'com.tencent.mm:id/bxz').clear().send_keys(word) # 微信8.0.16版本
|
|
|
driver.press_keycode(AndroidKey.ENTER)
|
|
|
Common.logger(log_type, crawler).info("进入搜索词页面")
|
|
|
Common.logging(log_type, crawler, env, "进入搜索词页面")
|
|
|
- driver.find_elements(By.ID, 'com.tencent.mm:id/br8')[0].click()
|
|
|
+ # driver.find_elements(By.ID, 'com.tencent.mm:id/br8')[0].click() # 微信8.0.30版本
|
|
|
+ driver.find_elements(By.ID, 'com.tencent.mm:id/jkg')[0].click() # 微信8.0.16版本
|
|
|
time.sleep(5)
|
|
|
|
|
|
# 切换到微信搜索结果页 webview
|
|
@@ -691,22 +696,22 @@ class ShipinhaoSearch:
|
|
|
def get_search_videos(cls, log_type, crawler, env):
|
|
|
user_list = cls.get_users(log_type, crawler, "wNgi6Z", env)
|
|
|
for user in user_list:
|
|
|
- try:
|
|
|
- cls.i = 0
|
|
|
- cls.download_cnt = 0
|
|
|
- search_word = user["search_word"]
|
|
|
- our_uid = user["our_uid"]
|
|
|
- Common.logger(log_type, crawler).info(f"开始抓取:{search_word}")
|
|
|
- Common.logging(log_type, crawler, env, f"开始抓取:{search_word}")
|
|
|
-
|
|
|
- cls.start_wechat(log_type=log_type,
|
|
|
- crawler=crawler,
|
|
|
- word=search_word,
|
|
|
- our_uid=our_uid,
|
|
|
- env=env)
|
|
|
- except Exception as e:
|
|
|
- Common.logger(log_type, crawler).error(f"抓取{user['search_word']}时异常:{e}\n")
|
|
|
- Common.logging(log_type, crawler, env, f"抓取{user['search_word']}时异常:{e}\n")
|
|
|
+ # try:
|
|
|
+ cls.i = 0
|
|
|
+ cls.download_cnt = 0
|
|
|
+ search_word = user["search_word"]
|
|
|
+ our_uid = user["our_uid"]
|
|
|
+ Common.logger(log_type, crawler).info(f"开始抓取:{search_word}")
|
|
|
+ Common.logging(log_type, crawler, env, f"开始抓取:{search_word}")
|
|
|
+
|
|
|
+ cls.start_wechat(log_type=log_type,
|
|
|
+ crawler=crawler,
|
|
|
+ word=search_word,
|
|
|
+ our_uid=our_uid,
|
|
|
+ env=env)
|
|
|
+ # except Exception as e:
|
|
|
+ # Common.logger(log_type, crawler).error(f"抓取{user['search_word']}时异常:{e}\n")
|
|
|
+ # Common.logging(log_type, crawler, env, f"抓取{user['search_word']}时异常:{e}\n")
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|