defsearch_company(self, company_name):#time.sleep(0.3)
try:
result={}
result[COMPANY.NAME]=utils.normalizeCompanyName(company_name)
logger.info("search for: %s" %(company_name,))"""self.driver.get("https://m.qichacha.com/")
self.driver.find_element_by_id("searchkey").send_keys(company_name)
# 单击搜索按钮
srh_btn = self.driver.find_element_by_xpath("//*[@id="V3_Index_S"]//span")
srh_btn.click()"""self.driver.get("https://m.qcc.com/search?key=%s" %(company_name))
utils.alertWait(WebDriverWait(self.driver,3).until,
expected_conditions.presence_of_element_located(
(By.XPATH,"//*[contains(@class,"text-danger") or contains(@class,"nodata")]")), 5, 0,"not found text-danger or nodata")#检测企业是不是存在
inc_full = self.driver.find_element_by_xpath("//*[@class="text-danger"]").text
self.error_encounter=0if inc_full == "0":
logger.error("company %s not found" %(company_name,))returnNone#获取首个企业文本
cname = self.driver.find_element_by_xpath("//div[@class="list-item-name"]").text
href= self.driver.find_element_by_xpath("//a[@class="a-decoration"]").get_attribute("href")#曾用名
cym =Nonetry:
stock_or_others= self.driver.find_element_by_xpath("//div[@class="list-item-bottom"]").text#print(stock_or_others)
#称呼不同:曾用名 或 历史股东等
if utils.normalizeCompanyName(company_name) instock_or_others:
company_bottom= stock_or_others.replace(":", ":")
cym= company_bottom.split(":")[1]except:#获取下面显示失败
pass
if utils.normalizeCompanyName(cname) ==utils.normalizeCompanyName(company_name)or utils.normalizeCompanyName(cym) ==utils.normalizeCompanyName(company_name):
result[COMPANY.URL]=href#time.sleep(0.2)
returnself.company_detail(href, result)exceptException as err:#self.driver.delete_all_cookies()
logger.error(err)
self.error_encounter= self.error_encounter + 1
if self.error_encounter >= 3:
self.driver.quit()
self.init()returnNonefinally:pass