| 28 | |
| 29 | |
| 30 | def search(): |
| 31 | try: |
| 32 | print('开始访问b站....') |
| 33 | browser.get("https://www.bilibili.com/") |
| 34 | |
| 35 | # 被那个破登录遮住了 |
| 36 | # index = WAIT.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#primary_menu > ul > li.home > a"))) |
| 37 | # index.click() |
| 38 | |
| 39 | input = WAIT.until(EC.presence_of_element_located((By.CSS_SELECTOR, "#nav_searchform > input"))) |
| 40 | submit = WAIT.until(EC.element_to_be_clickable( |
| 41 | (By.XPATH, '/html/body/div[2]/div/div[1]/div[1]/div/div[2]/div/form/div/button'))) |
| 42 | |
| 43 | input.send_keys('蔡徐坤 篮球') |
| 44 | submit.click() |
| 45 | |
| 46 | # 跳转到新的窗口 |
| 47 | print('跳转到新窗口') |
| 48 | all_h = browser.window_handles |
| 49 | browser.switch_to.window(all_h[1]) |
| 50 | get_source() |
| 51 | |
| 52 | total = WAIT.until(EC.presence_of_element_located((By.CSS_SELECTOR, |
| 53 | "#all-list > div.flow-loader > div.page-wrap > div > ul > li.page-item.last > button"))) |
| 54 | return int(total.text) |
| 55 | except TimeoutException: |
| 56 | return search() |
| 57 | |
| 58 | |
| 59 | def next_page(page_num): |