1 from selenium import webdriver
2 import time
3
4 from selenium.webdriver.common.keys import Keys
5
6 driver = webdriver.Chrome()
7 def zijie():
8 # 打开网站
9 driver.get("https://jobs.bytedance.com/campus/position")
10 time.sleep(1)
11 # #bd > section > section > main > div > div > div.header__36dmY > div > div.search-block.searchBlock__1mh35 > span > input
12 driver.find_element_by_css_selector("#bd > section > section > main > div > div > div.header__36dmY > div > div.search-block.searchBlock__1mh35 > span > input").send_keys("测试")
13 time.sleep(2)
14 driver.find_element_by_css_selector("#bd > section > section > main > div > div > div.header__36dmY > div > div.search-block.searchBlock__1mh35 > span > input").send_keys(Keys.ENTER)
15 time.sleep(2)
16 #判断查到的第一个结果有没有测试这个词
17 message = driver.find_element_by_css_selector('#bd > section > section > main > div > div > div.content__IN8vJ > div.rightBlock.rightBlock__2ZGFh > div.borderContainer__3S4gr > div.listItems__1q9i5 > a:nth-child(1) > div > div.title__37NOe.positionItem-title.sofiaBold > span').text
18 # 判断如果有这个文本信息,那么布尔值是真的,否则就是假的
19 # print(type(message))
20 # print(len(message))
21 result = "测试" in message
22 if (result):
23 print("搜索的结果中 包含测试这个词!")
24 else:
25 print("搜索的结果中 不包含测试这个词!")
26 if __name__ == '__main__':
27 zijie()
03-29
735
04-09
295
11-05
284