墊的腳本開源,懶得寫自動登錄了,用pycharm運行即可
# encoding = utf-8
from selenium import webdriver
from selenium.webdriver.common.by import By
import unittest
import time
class Search_KeyWords(unittest.TestCase):
? ?def setUp(self):
? ? ? ?self.driver = webdriver.Firefox()
? ? ? ?self.driver.implicitly_wait(30)
? ? ? ?self.url = "https://live.bilibili.com/26532808?broadcast_type=0&is_room_feed=1&spm_id_from=333.999.to_liveroom.0.click&live_from=86002"
? ?def test_search_davieyang(self):
? ? ? ?driver = self.driver
? ? ? ?driver.get(self.url)
? ? ? ?time.sleep(30)
? ? ? ?# driver.find_element(By.ID,'kw').clear()
? ? ? ?while True :
? ? ? ? ? ?driver.find_element(by="xpath",
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?value="/html/body/div[3]/main/div[1]/section[1]/div[3]/div[11]/div/div[2]/div[2]/textarea").send_keys("柚子")
? ? ? ? ? ?# driver.find_element(By.ID,'kw').send_keys('haoyun')
? ? ? ? ? ?driver.find_element(by="xpath",
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?value="/html/body/div[3]/main/div[1]/section[1]/div[3]/div[11]/div/div[3]/div/button/span").click()
? ? ? ? ? ?time.sleep(5)
? ? ? ? ? ?driver.find_element(by="xpath",
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?value="/html/body/div[3]/main/div[1]/section[1]/div[3]/div[11]/div/div[2]/div[2]/textarea").send_keys("是墊的")
? ? ? ? ? ?# driver.find_element(By.ID,'kw').send_keys('haoyun')
? ? ? ? ? ?driver.find_element(by="xpath",
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?value="/html/body/div[3]/main/div[1]/section[1]/div[3]/div[11]/div/div[3]/div/button/span").click()
? ? ? ? ? ?time.sleep(5)
? ? ? ? ? ?driver.find_element(by="xpath",
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?value="/html/body/div[3]/main/div[1]/section[1]/div[3]/div[11]/div/div[2]/div[2]/textarea").send_keys("柚子")
? ? ? ? ? ?# driver.find_element(By.ID,'kw').send_keys('haoyun')
? ? ? ? ? ?driver.find_element(by="xpath",
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?value="/html/body/div[3]/main/div[1]/section[1]/div[3]/div[11]/div/div[3]/div/button/span").click()
? ? ? ? ? ?time.sleep(5)
? ? ? ? ? ?driver.find_element(by="xpath",
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?value="/html/body/div[3]/main/div[1]/section[1]/div[3]/div[11]/div/div[2]/div[2]/textarea").send_keys("是墊的")
? ? ? ? ? ?# driver.find_element(By.ID,'kw').send_keys('haoyun')
? ? ? ? ? ?driver.find_element(by="xpath",
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?value="/html/body/div[3]/main/div[1]/section[1]/div[3]/div[11]/div/div[3]/div/button/span").click()
? ? ? ? ? ?time.sleep(5)
? ? ? ? ? ?driver.find_element(by="xpath",
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?value="/html/body/div[3]/main/div[1]/section[1]/div[3]/div[11]/div/div[2]/div[2]/textarea").send_keys("柚子是墊的")
? ? ? ? ? ?# driver.find_element(By.ID,'kw').send_keys('haoyun')
? ? ? ? ? ?driver.find_element(by="xpath",
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?value="/html/body/div[3]/main/div[1]/section[1]/div[3]/div[11]/div/div[3]/div/button/span").click()
? ? ? ? ? ?time.sleep(5)
? ? ? ? ? ?driver.find_element(by="xpath",
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?value="/html/body/div[3]/main/div[1]/section[1]/div[3]/div[11]/div/div[2]/div[2]/textarea").send_keys("柚子是墊的")
? ? ? ? ? ?# driver.find_element(By.ID,'kw').send_keys('haoyun')
? ? ? ? ? ?driver.find_element(by="xpath",
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?value="/html/body/div[3]/main/div[1]/section[1]/div[3]/div[11]/div/div[3]/div/button/span").click()
? ? ? ? ? ?time.sleep(5)
? ? ? ? ? ?driver.find_element(by="xpath",
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?value="/html/body/div[3]/main/div[1]/section[1]/div[3]/div[11]/div/div[2]/div[2]/textarea").send_keys("墊的墊的墊的墊的")
? ? ? ? ? ?# driver.find_element(By.ID,'kw').send_keys('haoyun')
? ? ? ? ? ?driver.find_element(by="xpath",
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?value="/html/body/div[3]/main/div[1]/section[1]/div[3]/div[11]/div/div[3]/div/button/span").click()
? ? ? ? ? ?time.sleep(5)
? ? ? ? ? ?driver.find_element(by="xpath",
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?value="/html/body/div[3]/main/div[1]/section[1]/div[3]/div[11]/div/div[2]/div[2]/textarea").send_keys("柚子是墊的")
? ? ? ? ? ?# driver.find_element(By.ID,'kw').send_keys('haoyun')
? ? ? ? ? ?driver.find_element(by="xpath",
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?value="/html/body/div[3]/main/div[1]/section[1]/div[3]/div[11]/div/div[3]/div/button/span").click()
? ? ? ? ? ?time.sleep(5)
? ? ? ? ? ?driver.find_element(by="xpath",
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?value="/html/body/div[3]/main/div[1]/section[1]/div[3]/div[11]/div/div[2]/div[2]/textarea").send_keys("???這下你們滿意了吧")
? ? ? ? ? ?# driver.find_element(By.ID,'kw').send_keys('haoyun')
? ? ? ? ? ?driver.find_element(by="xpath",
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?value="/html/body/div[3]/main/div[1]/section[1]/div[3]/div[11]/div/div[3]/div/button/span").click()
? ? ? ? ? ?time.sleep(5)
? ? ? ?# try:
? ? ? ?# ? ? self.assertTrue("haoyun" in driver.page_source)
? ? ? ?# except AssertionError as e:
? ? ? ?# ? ? raise e
? ?# def test_search_selenium(self):
? ?# ? ? driver = self.driver
? ?# ? ? driver.get(self.url)
? ?# ? ? driver.find_element(By.ID, 'kw').clear()
? ?# ? ? driver.find_element(By.ID, 'kw').send_keys('haoyun')
? ?# ? ? driver.find_element(By.ID, 'su').click()
? ?# ? ? time.sleep(3)
? ?# ? ? try:
? ?# ? ? ? ? self.assertTrue("hao" in driver.page_source)
? ?# ? ? except AssertionError as e:
? ?# ? ? ? ? raise e
? ?def tearDown(self):
? ? ? ?self.driver.quit()
if __name__ == "__main__":
? ?suite = unittest.TestSuite()
? ?suite.addTest(Search_KeyWords('test_search_davieyang'))
? ?# suite.addTest(Search_KeyWords('test_search_selenium'))
? ?runner = unittest.TextTestRunner()
? ?runner.run(suite)
# 斷言的結(jié)果是否出現(xiàn)在源代碼中