死亡公司公墓数据(IT桔子)

在这里插入图片描述
最近很火的死亡公司公墓
有些公司虽然已经死了,但是依然活在我们心中,比如上香第一的(斜眼笑)
今天带大家用selenium获取死亡公司数据

代码如下
drive = webdriver.Chrome()
url='https://www.itjuzi.com/deathCompany'
drive.get(url)
result=[]
count=1
next_page=drive.find_element_by_xpath('//*[@id="app"]/div[1]/div/div/div/div[2]/div/div[3]/div[2]/div/div/button[2]')#下一页
while next_page.is_enabled():#判断下一页是否可用
    links = drive.find_element_by_tag_name("tbody").find_elements_by_tag_name("tr")#获取当前页面公司数量
    num=len(links)
    for i in range(1,num+1):
        gsjc=drive.find_element_by_xpath('//tbody/tr[%s]/td[3]/div/h5/a'%i).text#获取公司简称
        ch_time=drive.find_element_by_xpath('//tbody/tr[%s]/td[3]/div/p'%i).text#获取存活时间
        close_time=drive.find_element_by_xpath('//tbody/tr[%s]/td[4]'%i).text#获取关闭时间
        hy=drive.find_element_by_xpath('//tbody/tr[%s]/td[5]'%i).text#获取所属行业
        dd=drive.find_element_by_xpath('//tbody/tr[%s]/td[6]'%i).text#获取公司地点
        clsj=drive.find_element_by_xpath('//tbody/tr[%s]/td[7]'%i).text#获取关闭时间
        rz=drive.find_element_by_xpath('//tbody/tr[%s]/td[8]'%i).text#获取融资状态
        result.append([gsjc,ch_time,close_time,hy,dd,clsj,rz])#添加到嵌套列表
    print("第 %s 页爬取完成"%count)
    drive.find_element_by_xpath('//*[@id="app"]/div[1]/div/div/div/div[2]/div/div[3]/div[2]/div/div/button[2]').click()#点击下一页
    tm=random.uniform(2,5)#生成随机数
    time.sleep(tm)#随机休眠
    count+=1#页数+1
pd_result=pd.DataFrame(result)
pd_result.columns=['公司简称','存活时间','关闭时间','行业','地点','成立时间','获投状态']
pd_result.to_excel("IT桔子死亡公墓.xlsx",index=False)
发布了35 篇原创文章 · 获赞 35 · 访问量 2594

猜你喜欢

转载自blog.csdn.net/qq_35866846/article/details/103391949