Python爬虫天眼查
最近没事做,抱着试一试的心态做了一个天眼查的爬虫。用的Selenium。
首先需要做登录,所以我选择Selenium,Python代码如下
time.sleep(2)
driver.find_element_by_class_name("link-hover-click").click()
time.sleep(1)
driver.find_element_by_xpath("//div[text()='账号密码登录']").click()
time.sleep(1)
driver.find_element_by_xpath("//div[@class='pb30 position-rel']//input[@class='_input input_nor contactphone']").send_keys("********")
driver.find_element_by_xpath("//div[@class='pb40 position-rel']//input[@class='_input input_nor contactword']").send_keys("********")
driver.find_element_by_xpath("//div[@class='modulein modulein1 mobile_box pl15 pr15 f-base collapse in']//div[@class='c-white b-c9 pt8 f18 text-center login_btn']").click()
time.sleep(1)
driver.execute_script("window.scrollTo(0, document.body.scrollHeight)")
time.sleep(2)
登录之后就是解析页面,获取我们要的元素,Python代码如下
#获取公司地址的正则
stdz="""<span class="site">(.*?)</span>"""
#获取公司名称
stgs=r"""<a class="name " tyc-event-click="" tyc-event-ch="CompanySearch.Company" href=".*?" target="_blank">(.*?)</a>"""
#获取代表人
stdb=r"""<div class="title text-ellipsis">法定代表人:<a title=".*?" class="legalPersonName hover_underline" target="_blank" href=".*?">(.*?)</a></div>"""
#获取注册金额
stzc="""<div class="title text-ellipsis">注册资本:<span title=".*?">(.*?)</span></div>"""
#获取注册时间
stsj="""<div class="title text-ellipsis">注册时间:<span title=".*?">(.*?)</span></div>"""
#获取电话
stdh="""<span class="link-hover-click">([\d]+|[\d]+[-][\d]+)</span>"""
#获取邮箱
steml="""<span class="label">邮箱:</span><span class="link-hover-click">(.*?)</span>"""
最后把数据写入xls文件即可。
爬取结果如下,一次运行约有2500+数据。如有需要可以联系QQ:3412749634