{"id":21288605,"url":"https://github.com/srx-2000/swaiter","last_synced_at":"2026-05-18T06:05:38.634Z","repository":{"id":165931102,"uuid":"641332692","full_name":"srx-2000/Swaiter","owner":"srx-2000","description":"a programe to wait until the selenium element has loaded——selenium模拟器元素等待程序","archived":false,"fork":false,"pushed_at":"2023-05-22T03:58:59.000Z","size":6,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-24T06:22:37.428Z","etag":null,"topics":["crawler","selenium","selenium-python"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/Swaiter/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/srx-2000.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-16T08:55:44.000Z","updated_at":"2023-07-15T02:49:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"0d7c48b0-16fe-4253-b61d-37ce854fa56b","html_url":"https://github.com/srx-2000/Swaiter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/srx-2000/Swaiter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srx-2000%2FSwaiter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srx-2000%2FSwaiter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srx-2000%2FSwaiter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srx-2000%2FSwaiter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/srx-2000","download_url":"https://codeload.github.com/srx-2000/Swaiter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srx-2000%2FSwaiter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274134844,"owners_count":25228199,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-08T02:00:09.813Z","response_time":121,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crawler","selenium","selenium-python"],"created_at":"2024-11-21T12:23:14.411Z","updated_at":"2026-05-18T06:05:33.602Z","avatar_url":"https://github.com/srx-2000.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Swaiter\n\n​\t项目名字取自：Selenium+waiter\n\n​\t作为一个爬虫人，在使用selenium进行爬虫时，时长会遇到由于网络等原因导致无法及时获取一些元素，从而导致程序报错。此时聪明的小伙伴就会说了：加个`time.sleep()`不就好了。事实上这个方法确实可以解决绝大部分问题，但其也有一个比较尴尬的问题：到底要“睡”多久合适？长了耽误爬取效率，短了又怕没有作用，所以这个库就是为了解决上述问题而存在的。\n\n## 安装\n\n库的安装十分简单直接使用以下面的命令就可以安装成功了：\n\n```bash\npip install Swaiter\n```\n\n## 使用\n\n使用方法主要分为两种：直接使用基础组件进行开发、继承并添加自己的检索函数\n\n### 使用基础组件\n\n这里给一个简单的使用基础组件的例子：\n\n```python\nfrom selenium.webdriver import Chrome\nfrom selenium.webdriver.chrome.options import Options\nfrom waiter import Waiter\n\nif __name__ == '__main__':\n    # 获取selenium中驱动配置项（可省略）\n    driver_opt = Options()\n    url = \"https://www.baidu.com/\"\n    # 获取selenium中的driver对象\n    chrome_driver = Chrome(options=driver_opt)\n    chrome_driver.get(url=url)\n    # 利用获取到的driver对象创建Waiter对象\n    w = Waiter(chrome_driver)\n    # 传入xpath路径以及查询参数，检索input对象，并向其中填入查询参数\n    w.input_send_waiter(xpath=\"//input[@id='kw']\", query=\"python\")\n    # 利用xpath找到点击对象，模拟点击\n    w.click_waiter(xpath=\"//input[@id='su']\")\n    # 在新的页面找到第一个链接，并获取其中的href属性值\n    result = w.elements_text_waiter(xpath=\"//h3/a[@tabindex=0]\", attribute=\"href\")\n    print(result)\n```\n\n​\t上述例子中，使用了3个基础的搜索函数，向这样的搜索函数，本库一共提供了5个，应该可以满足简单的模拟需求，当然如果你有一些特别的搜索需求，也可以尝试使用第二种方式。\n\n### 继承并开发自己的检索函数\n\n```python\nfrom waiter import Waiter\nfrom selenium.webdriver.common.by import By\n\nclass MyWaiter(Waiter):\n    def __init__(self, driver, interval, is_track, is_log):\n        super().__init__(driver=driver, interval=interval, is_track=is_track, is_log=is_log)\n\n    def _textarea_send(self, xpath, **kwargs):\n        self.driver.find_element(By.XPATH, xpath).send(kwargs)\n\n    def textarea_send(self, xpath, **kwargs):\n        self.wait(func=\"_textarea_send\", xpath=xpath, interval=5, **kwargs)\n```\n\n## 环境\n\n\u003e window10、window11\n\u003e\n\u003e python\u003e=3.8\n\u003e\n\u003e selenium\u003e=4.9.0\n\u003e\n\u003e loguru\u003e=0.7.0\n\n## 版本\n\n#### 2023.5.22\n\n**Version-1.0.4**\n\n- 添加select组件的搜索器\n  - 添加获取组件所有选项\n  - 添加向select组件中输入值\n\n[1.0.4](https://pypi.org/project/Swaiter/1.0.4/)\n\n#### 2023.5.16\n\n**Version-1.0.3**\n\n完成基础功能\n\n[1.0.3](https://pypi.org/project/Swaiter/1.0.3/)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsrx-2000%2Fswaiter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsrx-2000%2Fswaiter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsrx-2000%2Fswaiter/lists"}