欢迎光临散文网 会员登陆 & 注册

垫的脚本开源,懒得写自动登录了,用pycharm运行即可

2023-04-01 14:19 作者:柚さぎ-yosagi  | 我要投稿

# 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)
# 断言的结果是否出现在源代码中

垫的脚本开源,懒得写自动登录了,用pycharm运行即可的评论 (共 条)

分享到微博请遵守国家法律