个人博客转至:tybai.com

无聊就想打码,打码使我快乐


Fork me on GitHub

python_selenium智联搜索

python_selenium智联搜索

去招聘会工作,奈何网上仅仅提供招聘会的公司名字,没有提供招聘的职位,SO我写了个小代码给别人在智联上面搜索职位,由于时间紧迫,前程的就不写了

#!/usr/bin/python3.4
# -*- coding: utf-8 -*-

from selenium import webdriver
from lxml import etree
import time


# 打开浏览器
def openbrowser(keyword):
    global browser

    # 打开谷歌浏览器
    # Firefox()
    # Chrome()
    # browser = webdriver.Chrome()

    options = webdriver.ChromeOptions()
    prefs = {
        'profile.default_content_setting_values': {
            'images': 2
        }
    }
    options.add_experimental_option('prefs', prefs)
    browser = webdriver.Chrome(chrome_options=options)
    try:
        browser.find_element_by_id("KeyWord_kw2").send_keys(keyword)
        browser.find_element_by_class_name("doSearch").click()

        time.sleep(5)
        htmlcontent = browser.page_source

        browser.quit()
    except:

        url = "http://www.zhaopin.com/"
        browser.get(url)
        # 打开浏览器时间
        # print("等待10秒打开浏览器...")
        # time.sleep(10)
        browser.find_element_by_id("KeyWord_kw2").send_keys(keyword)
        browser.find_element_by_class_name("doSearch").click()

        time.sleep(5)
        htmlcontent = browser.page_source
        browser.quit()

    return htmlcontent


def analyzehtml(html):
    info = []
    page = etree.HTML(html.lower())
    hrefs = page.xpath('//a[@style="font-weight: bold"]/text()')
    for href in hrefs:
        info.append(href)

    return info


if __name__ == "__main__":
    file = open("../txt/company.txt")
    companys = file.readlines()
    for keyword in companys:
        print(keyword.strip())
        html = openbrowser(keyword.strip())
        a = analyzehtml(html)
        a.insert(0, str(keyword.strip()))
        print(a)
        b = "&&".join(a)
        if len(b)==0:
            b = "智联没有找到该公司"
        
        filewrite = open("../txt/qwe.txt", "a")
        filewrite.write("\n" + str(b))
        filewrite.close()

posted on 2016-12-05 21:22  TTyb  阅读(...)  评论(...编辑  收藏

导航


不用多久

我就会升职加薪

当上总经理

出任CEO

迎娶白富美

走上人生巅峰

Pulpit rock