当前位置: 代码迷 >> 综合 >> python3.7,Selenium + webdriver.Chrome 获取腾讯求职信息二
  详细解决方案

python3.7,Selenium + webdriver.Chrome 获取腾讯求职信息二

热度:44   发布时间:2023-12-12 22:19:45.0

经过一天的调试,终于不再出现线程的问题了
大概思路是这样的: 测试单元启动后,添加一个 8 秒的执行时长,从而有足够的时间腾出来打开窗口,关闭窗口,拿到自己想要的数据,这里有一个新的问题就是: 爬取的时间并不是非常契合 (腾讯出求职的信息更新真的相当快哇)

# -*- coding=utf-8 -*-
import threading
import time
import unittest
from selenium import webdriver
from queue import Queue
import warnings
warnings.simplefilter("ignore", ResourceWarning)'''腾讯职位的前 10 位数据, 并写入 excel, 每页有 10 条信息https://careers.tencent.com/search.html?query=co_1&sc=1(https://careers.tencent.com/search.html?query=co_1&index=1&sc=1)https://careers.tencent.com/search.html?query=co_1&index=2&sc=1https://careers.tencent.com/search.html?query=co_1&index=3&sc=1 # 第一页的 URL'''class ThreadParse(threading.Thread):def __init__(self, thread_name, list_queue):super(ThreadParse, self).__init__()self.thread_name = thread_nameself.list_queue = list_queue# self.driver = driverdef run(self):try:time.sleep(5)self.driver = webdriver.Chrome(executable_path="D:\Python_module\chromdriver\chromedriver.exe")self.driver.maximize_window()page_nmb = self.list_queue.get(False)url = "https://careers.tencent.com/search.html?query=co_1&index=" + str(page_nmb) + "&sc=1"print("此时的 URL 是: " + url)self.driver.get(url)time.sleep(2)self.driver.find_elements_by_class_name("recruit-title")[1].click()time.sleep(5)handle_list = self.driver.window_handlesself.driver.switch_to.window(handle_list[1])job_content = self.driver.find_elements_by_class_name("work-module")print(job_content[0].text)print(job_content[1].text)self.driver.close()self.driver.switch_to.window(handle_list[0])self.driver.quit()time.sleep(5)# self.driver.switch_to.window(handle_list[0])# self.driver.close()except Exception as e:print(e)class Tencent(unittest.TestCase):def setUp(self):  # 初始化方法pass# self.driver = webdriver.Chrome(executable_path="D:\Python_module\chromdriver\chromedriver.exe")# self.driver.maximize_window()def testTencent(self):  # 测试方法 ,test 开头# self.driver.get("https://www.baidu.com")list_queue = Queue(3)for i in range(1, 4):print("放放了: " + str(i))list_queue.put(i, 2)crawl_list = []for i in range(1, 4):thread_name = "Thread: " + str(i)thread = ThreadParse(thread_name, list_queue)thread.start()time.sleep(8)crawl_list.append(thread)time.sleep(3)while not list_queue.empty():print("队列还在进行中: " + str(list_queue.get()))for thread in crawl_list:print("等待线程: " + str(thread.thread_name) + " 的执行")thread.join()time.sleep(5)def crawl(self, page_nmb):print(page_nmb)self.driver.get("https://careers.tencent.com/search.html?query=co_1&index=" + str(page_nmb) + "&sc=1")self.driver.find_elements_by_class_name("recruit-title")[1].click()handle_list = self.driver.window_handlesself.driver.switch_to.window(handle_list[1])time.sleep(2)job_content = self.driver.find_elements_by_class_name("work-module")print(job_content[0].text)print(job_content[1].text)self.driver.close()self.driver.switch_to.window(handle_list[0])# self.driver.switch_to.window(handle_list[0])# self.driver.close()def tearDown(self):# self.driver.quit() # 退出 driver.Chrome()passif __name__ == "__main__":unittest.main()

运行结果如下:

D:\Python37-32\python.exe “C:\Program Files\JetBrains\PyCharm Community Edition 2021.1.2\plugins\python-ce\helpers\pycharm_jb_unittest_runner.py” --target test.Tencent.testTencent
Testing started at 3:25 PM …
Launching unittests with arguments python -m unittest test.Tencent.testTencent in D:\pyFile
Process finished with exit code 0
放放了: 1
放放了: 2
放放了: 3
此时的 URL 是: https://careers.tencent.com/search.html?query=co_1&index=1&sc=1
工作职责
1.结合市场需求及部门业务目标,制定产品的商业化框架;
2.协同多部门制定运营方案,提升产品关键数据,维护用户长期留存;
工作要求
1 7年以上卡牌游戏研发/运营工作经历,有卡牌研发项目核心成员经验者优先
2 深度理解卡牌游戏品类,对产品沿革及未来发展方向有清晰认知;
3.熟悉产品研发逻辑,了解二次元用户习惯及市场需求;
4.团队合作意识佳,逻辑思考能力强;
5.熟悉卡牌游戏的商业化方案,如阴阳师/赛马娘/碧蓝幻想等
此时的 URL 是: https://careers.tencent.com/search.html?query=co_1&index=2&sc=1
工作职责
1、负责腾讯云政法行业ISV的合作生态构建和运营管理;
2、推动政法行业合作伙伴及优秀产品/解决方案引入;
3、规划和推进重点场景的商业模式分析、联合ISV推进联合产品/联合解决方案的打造;
4、推动联合产品方案的市场策略分析,推动与ISV伙伴的互利共赢,共同成长。
工作要求
1、 全日制本科及以上学历,计算机、电信相关专业;
2、 五年以上公检法司、应急、网信行业工作经验,熟悉行业背景及发展趋势;
3、 具有丰富的ISV拓展、渠道建设和行业ISV运营管理经验;
4、 具有一定IT产品、技术方面的知识储备;对于云计算、大数据、AI、区块链等有一定的了解和认识;
5、 思维逻辑清晰,敏锐的行业洞察力,强自我驱动力和执行力;
6、 有一定行业资源优先;
7、 公检法司、应急、网信行业大厂工作或互联行业大厂从事相关岗位者优先。
此时的 URL 是: https://careers.tencent.com/search.html?query=co_1&index=3&sc=1
等待线程: Thread: 1 的执行
工作职责
负责评估腾讯云/腾讯自研上云业务应用(C/C++/Go)的编译优化机会;
负责编译优化技术的落地与创新;
负责ARM arm64体系结构的编译支持和业务兼容方案的创新。
工作要求
本科以上学历;
2年以上编译器研发或编译优化工作经验;
熟悉LLVM/GCC/Open JDK Hotspot/Graal等编译工具/框架;
熟悉Intel/AMD x86_64 或 ARM arm64体系结构;
精通C/C++, 具备出色的系统编程能力。
有以下经验者优先:
具备基于采样的编译优化技术(如: PGO/AutoFDO/Bolt等)实际项目工作经验者优先;
具备Just In Time编译技术或代码注入研发经验者优先;
具备ARM平台编译后端支持项目经验优先。
等待线程: Thread: 2 的执行
等待线程: Thread: 3 的执行
Ran 1 test in 50.249s
OK

  相关解决方案