zoukankan      html  css  js  c++  java
  • 模拟登陆+数据爬取 (python+selenuim)

    以下代码是用来爬取LinkedIn网站一些学者的经历的,仅供参考,注意:不要一次性大量爬取会被封号,不要问我为什么知道

    #-*- coding:utf-8 -*-
    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    import time
    from bs4 import BeautifulSoup
    
    diver=webdriver.Chrome()
    diver.get('https://www.linkedin.com/')
    #等待网站加载完成
    time.sleep(1)
    #模拟登陆
    diver.find_element_by_id('login-email').send_keys(用户名)
    diver.find_element_by_id('login-password').send_keys(密码)
    # 点击跳转
    diver.find_element_by_id('login-submit').send_keys(Keys.ENTER)
    time.sleep(1)
    #查询
     diver.find_element_by_tag_name('input').send_keys(学者名)
    diver.find_element_by_tag_name('input').send_keys(Keys.ENTER)
    time.sleep(1)
    #获取当前页面所有可能的人
    soup=BeautifulSoup(diver.page_source,'lxml')
    items=soup.findAll('div',{'class':'search-result__wrapper'})
    n=0
    for i in items:
    n+=1
    title=i.find('div',{'class':'search-result__image-wrapper'}).find('a')['href']
    diver.get('https://www.linkedin.com'+title)
    time.sleep(3)
    Soup=BeautifulSoup(diver.page_source,'lxml')
    # print Soup
    Items=Soup.findAll('li',{'class':'pv-profile-section__card-item pv-position-entity ember-view'})
    print str(n)+':'
    for i in Items:
        print i.find('div',{'class':'pv-entity__summary-info'}).get_text().replace('
    ','')
    diver.close()
  • 相关阅读:
    mysql乐观锁总结和实践
    linux使用文本编辑器vi常用命令
    python高级特性-sorted()
    python高级特性-filter
    Python函数式编程-map/reduce
    centos 7.3 快速安装ceph
    python高级特性-迭代器
    python高级特性-生成器
    python高级特性-列表生成
    python高级特性-迭代
  • 原文地址:https://www.cnblogs.com/ybf-yyj/p/8059171.html
Copyright © 2011-2022 走看看