def get_raw_meta_texts(url): print('running Chrome...') c = Chrome() c.get(url) _scroll_to_the_bottom_google_image_search(c) print('exacting by xpath...') elements = c.xpath_lxml('//*[@class = "rg_meta notranslate"]') raw_meta_texts = list(map(lambda x: x.text_content(), elements)) c.quit() return raw_meta_texts
def test_access(): url = "https://b2b-ch.infomart.co.jp/company/search/list.page?1942&chi=23&cha=13" from selenium.webdriver import ActionChains from selenium.webdriver.common.keys import Keys c = Chrome() actions = ActionChains(c) c.get(url) links = c.find_elements_by_xpath("//a[@id='lnkCompanyName']") main_tab = c.current_window_handle for link in links: actions.key_down(Keys.CONTROL).click(link).key_up( Keys.CONTROL).perform() while True: try: c.switch_tab(index=1) xpath_ = "//div[@class='co-detail-tbl-row']" rows = c.find_elements_by_xpath(xpath_) if len(rows) == 0: raise text = c.find_element_by_xpath("//div[@class='main-area']") print(text.text) # tab.close() c.close() # len_ = len(c.window_handles) # while True: # c.close_tab() # if len(c.window_handles) == 1: # break c.switch_to_window(main_tab) except (Exception, ) as e: print(e) else: break c.quit()