python爬取启信宝_Python爬虫:爬取无账号无限制获取企查查信息

该博客介绍了如何使用Python爬虫无账号无限制地获取企查查上的公司信息。首先,通过`search_company`函数输入公司名称进行搜索,然后定位并点击搜索按钮。接着,检查企业是否存在,如果存在则获取公司名称、链接等信息。如果找到匹配的公司名称,进一步获取详细信息。如果出现错误,会进行错误处理和重试。
摘要由CSDN通过智能技术生成

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值