├── .gitattributes ├── .history ├── README_20250309061803.md ├── README_20250309061807.md ├── README_20250309062508.md ├── README_20250309062815.md ├── README_20250309063402.md ├── README_20250309063803.md ├── README_20250309064404.md ├── README_20250309070210.md ├── README_20250309070942.md ├── README_20250309071334.md ├── auto_phone_fill_20250309061744.py ├── auto_phone_fill_20250309061747.py ├── auto_phone_fill_20250309061808.py ├── auto_phone_fill_20250309062452.py ├── auto_phone_fill_20250309062459.py ├── auto_phone_fill_20250309062759.py ├── auto_phone_fill_20250309062921.py ├── auto_phone_fill_20250309063347.py ├── auto_phone_fill_20250309063355.py ├── auto_phone_fill_20250309063745.py ├── auto_phone_fill_20250309063815.py ├── auto_phone_fill_20250309064340.py ├── auto_phone_fill_20250309065817.py ├── auto_phone_fill_20250309070144.py ├── auto_phone_fill_20250309070215.py ├── auto_phone_fill_20250309070507.py ├── auto_phone_fill_20250309070511.py ├── auto_phone_fill_20250309070918.py ├── auto_phone_fill_20250309070953.py ├── auto_phone_fill_20250309071308.py ├── auto_phone_fill_20250309071400.py ├── auto_phone_fill_20250309071633.py ├── auto_phone_fill_20250309071634.py ├── auto_phone_fill_20250309071912.py ├── auto_phone_fill_20250309072330.py ├── auto_phone_fill_20250309072347.py ├── auto_phone_fill_20250309072659.py ├── auto_phone_fill_20250309072718.py ├── auto_phone_fill_20250309074850.py ├── auto_phone_fill_20250309080119.py ├── auto_phone_fill_20250309080622.py ├── auto_phone_fill_20250309080827.py ├── auto_phone_fill_20250309081108.py ├── auto_phone_fill_20250309081132.py ├── auto_phone_fill_20250309082028.py ├── auto_phone_fill_20250309082131.py ├── auto_phone_fill_20250309082732.py ├── auto_phone_fill_20250309083213.py ├── auto_phone_fill_20250309083444.py ├── auto_phone_fill_20250309083532.py ├── auto_phone_fill_20250309084101.py ├── auto_phone_fill_20250309084127.py ├── auto_phone_fill_20250309095521.py ├── auto_phone_fill_20250309095540.py ├── auto_phone_fill_20250309095600.py ├── auto_phone_fill_20250309095610.py ├── auto_phone_fill_20250309095736.py ├── auto_phone_fill_20250309095800.py ├── auto_phone_fill_20250309100026.py ├── auto_phone_fill_20250309100028.py ├── auto_phone_fill_20250309100102.py ├── auto_phone_fill_20250309100105.py ├── auto_phone_fill_20250309100131.py ├── auto_phone_fill_20250309100413.py ├── auto_phone_fill_20250309101308.py ├── auto_phone_fill_20250309101337.py ├── auto_phone_fill_20250309101351.py ├── auto_phone_fill_20250309101646.py ├── auto_phone_fill_20250309101651.py ├── auto_phone_fill_20250309102302.py ├── auto_phone_fill_20250309102325.py ├── auto_phone_fill_20250309102721.py ├── auto_phone_fill_20250309102726.py ├── auto_phone_fill_20250309103145.py ├── auto_phone_fill_20250309103211.py ├── auto_phone_fill_20250309103706.py ├── auto_phone_fill_20250309103715.py ├── auto_phone_fill_20250309104335.py ├── auto_phone_fill_20250309104352.py ├── auto_phone_fill_20250309104358.py ├── auto_phone_fill_20250309104454.py ├── auto_phone_fill_20250309104528.py ├── auto_phone_fill_20250309104544.py ├── auto_phone_fill_20250309104548.py ├── auto_phone_fill_20250309104602.py ├── auto_phone_fill_20250309104607.py ├── auto_phone_fill_20250309104736.py ├── auto_phone_fill_20250309104741.py ├── auto_phone_fill_20250309104922.py ├── auto_phone_fill_20250309105131.py ├── auto_phone_fill_20250309105149.py ├── auto_phone_fill_20250309105531.py ├── auto_phone_fill_20250309105633.py ├── auto_phone_fill_20250309110327.py ├── auto_phone_fill_20250309110341.py ├── auto_phone_fill_20250309110742.py ├── auto_phone_fill_20250309110802.py ├── auto_phone_fill_20250309110917.py ├── auto_phone_fill_20250309110936.py ├── auto_phone_fill_20250309141112.py ├── auto_phone_fill_20250309141128.py ├── auto_phone_fill_20250309141841.py ├── auto_phone_fill_20250309141859.py ├── auto_phone_fill_20250309142130.py ├── auto_phone_fill_20250309142145.py ├── auto_phone_fill_20250309142345.py ├── auto_phone_fill_20250309142417.py ├── auto_phone_fill_20250309142606.py ├── auto_phone_fill_20250309142613.py ├── auto_phone_fill_20250309142922.py ├── auto_phone_fill_20250309142939.py ├── auto_phone_fill_20250309143135.py ├── auto_phone_fill_20250309143407.py ├── auto_phone_fill_20250309143409.py ├── auto_phone_fill_20250309144546.py ├── auto_phone_fill_20250309144650.py ├── auto_phone_fill_20250309145608.py ├── auto_phone_fill_20250309145629.py ├── auto_phone_fill_20250309145907.py ├── auto_phone_fill_20250309145923.py ├── auto_phone_fill_20250309150934.py ├── auto_phone_fill_20250309151003.py ├── auto_phone_fill_20250309151009.py ├── auto_phone_fill_20250309151106.py ├── auto_phone_fill_20250309151121.py ├── auto_phone_fill_20250309151135.py ├── auto_phone_fill_20250309151156.py ├── auto_phone_fill_20250309151251.py ├── auto_phone_fill_20250309151403.py ├── auto_phone_fill_20250309151439.py ├── auto_phone_fill_20250309151441.py ├── auto_phone_fill_20250309152359.py ├── auto_phone_fill_20250309152420.py ├── auto_phone_fill_20250309152459.py ├── auto_phone_fill_20250309152501.py ├── auto_phone_fill_20250309152525.py ├── auto_phone_fill_20250309152851.py ├── auto_phone_fill_20250309153317.py ├── auto_phone_fill_20250309153548.py ├── auto_phone_fill_20250309153642.py ├── auto_phone_fill_20250309153653.py ├── auto_phone_fill_20250309154149.py ├── auto_phone_fill_20250309154326.py ├── auto_phone_fill_20250309154353.py ├── auto_phone_fill_20250309154817.py ├── auto_phone_fill_20250309154844.py ├── auto_phone_fill_20250309154851.py ├── auto_phone_fill_20250309154904.py ├── auto_phone_fill_20250309155317.py ├── auto_phone_fill_20250309155340.py ├── auto_phone_fill_20250309155353.py ├── auto_phone_fill_20250309155739.py ├── auto_phone_fill_20250309155749.py ├── auto_phone_fill_20250309160142.py ├── auto_phone_fill_20250309160144.py ├── auto_phone_fill_20250309160300.py ├── auto_phone_fill_20250309160313.py ├── auto_phone_fill_20250309160327.py ├── auto_phone_fill_20250309160340.py ├── auto_phone_fill_20250309160341.py ├── auto_phone_fill_20250309160355.py ├── auto_phone_fill_20250309160358.py ├── auto_phone_fill_20250309160414.py ├── auto_phone_fill_20250309160443.py ├── auto_phone_fill_20250309160609.py ├── auto_phone_fill_20250309160630.py ├── auto_phone_fill_20250309160637.py ├── auto_phone_fill_20250309160721.py ├── auto_phone_fill_20250309160736.py ├── auto_phone_fill_20250309160749.py ├── auto_phone_fill_20250309160804.py ├── auto_phone_fill_20250309161105.py ├── auto_phone_fill_20250309161133.py ├── auto_phone_fill_20250309161140.py ├── auto_phone_fill_20250309161216.py ├── auto_phone_fill_20250309161239.py ├── auto_phone_fill_20250309161300.py ├── auto_phone_fill_20250309161312.py ├── auto_phone_fill_20250309161319.py ├── auto_phone_fill_20250309161358.py ├── auto_phone_fill_20250309161401.py ├── auto_phone_fill_20250309161427.py ├── auto_phone_fill_20250309161500.py ├── auto_phone_fill_20250309161501.py ├── auto_phone_fill_20250309161621.py ├── auto_phone_fill_20250309161654.py ├── auto_phone_fill_20250309161800.py ├── auto_phone_fill_20250309162156.py ├── auto_phone_fill_20250309162204.py ├── auto_phone_fill_20250309162221.py ├── auto_phone_fill_20250309162235.py ├── auto_phone_fill_20250309162415.py ├── auto_phone_fill_20250309162633.py ├── auto_phone_fill_20250309162727.py ├── browser_launcher_20250309085101.py ├── browser_launcher_20250309085105.py ├── browser_launcher_20250309085528.py ├── click_api_key_20250309104713.py ├── click_api_key_20250309104717.py ├── click_api_key_20250309104922.py ├── data_cleaner_20250309081405.py ├── data_cleaner_20250309081408.py ├── data_cleaner_20250309081809.py ├── requirements_20250309061752.txt ├── requirements_20250309061755.txt ├── requirements_20250309062118.txt ├── requirements_20250309070045.txt ├── simple_browser_20250309090652.py ├── simple_browser_20250309090656.py ├── simple_browser_20250309091118.py ├── simple_browser_20250309095208.py ├── simple_cleaner_20250309081419.py ├── simple_cleaner_20250309081423.py └── simple_cleaner_20250309081730.py ├── .idea ├── .gitignore ├── autore.iml ├── inspectionProfiles │ ├── Project_Default.xml │ └── profiles_settings.xml ├── misc.xml └── modules.xml ├── README.md ├── __pycache__ └── auto_phone_fill.cpython-310.pyc ├── auto_phone_fill.py ├── browser_launcher.py ├── data_cleaner.py ├── main.py ├── requirements.txt ├── simple_browser.py └── simple_cleaner.py /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.history/README_20250309061803.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.history/README_20250309061807.md: -------------------------------------------------------------------------------- 1 | # SiliconFlow自动填写手机号脚本 2 | 3 | 这个Python脚本可以自动打开SiliconFlow的登录页面并填写手机号码。 4 | 5 | ## 安装依赖 6 | 7 | 在使用脚本之前,请确保安装所有必要的依赖: 8 | 9 | ```bash 10 | pip install -r requirements.txt 11 | ``` 12 | 13 | ## 使用方法 14 | 15 | 1. 打开`auto_phone_fill.py`文件 16 | 2. 在文件底部修改`phone_number`变量的值,将其替换为您想要填写的手机号码 17 | 3. 运行脚本: 18 | 19 | ```bash 20 | python auto_phone_fill.py 21 | ``` 22 | 23 | ## 注意事项 24 | 25 | - 脚本默认会打开Chrome浏览器窗口,如需以无头模式运行(不显示浏览器窗口),请取消注释相应代码行 26 | - 脚本执行后浏览器默认不会自动关闭,以便您查看结果,如需自动关闭,请取消注释相应代码行 27 | - 网页元素定位可能会因网站变更而失效,如遇问题请根据错误信息调整XPATH选择器 -------------------------------------------------------------------------------- /.history/README_20250309062508.md: -------------------------------------------------------------------------------- 1 | # SiliconFlow自动填写手机号脚本 2 | 3 | 这个Python脚本可以自动打开SiliconFlow的登录页面并填写手机号码。支持同时打开多个浏览器实例。 4 | 5 | ## 安装依赖 6 | 7 | 在使用脚本之前,请确保安装所有必要的依赖: 8 | 9 | ```bash 10 | pip install -r requirements.txt 11 | ``` 12 | 13 | ## 使用方法 14 | 15 | ### 单浏览器模式(已弃用) 16 | ~~1. 打开`auto_phone_fill.py`文件~~ 17 | ~~2. 在文件底部修改`phone_number`变量的值,将其替换为您想要填写的手机号码~~ 18 | ~~3. 运行脚本:~~ 19 | 20 | ### 多浏览器模式(当前模式) 21 | 1. 打开`auto_phone_fill.py`文件 22 | 2. 在文件底部找到`phone_numbers`列表,替换为您想要填写的手机号码: 23 | ```python 24 | phone_numbers = [ 25 | "13800138001", # 第一个浏览器填写的手机号 26 | "13800138002", # 第二个浏览器填写的手机号 27 | "13800138003", # 第三个浏览器填写的手机号 28 | ] 29 | ``` 30 | 3. 您可以增加或减少列表中的手机号数量,以控制打开的浏览器数量 31 | 4. 运行脚本: 32 | 33 | ```bash 34 | python auto_phone_fill.py 35 | ``` 36 | 37 | ## 注意事项 38 | 39 | - 脚本默认会打开Chrome浏览器窗口,如需以无头模式运行(不显示浏览器窗口),请取消注释相应代码行 40 | - 脚本执行后浏览器默认不会自动关闭,以便您查看结果,如需自动关闭,请取消注释相应代码行 41 | - 网页元素定位可能会因网站变更而失效,如遇问题请根据错误信息调整XPATH选择器 42 | - 在多浏览器模式下,脚本会依次启动浏览器并填写相应的手机号码,每个浏览器之间有1秒的延迟以避免资源竞争 -------------------------------------------------------------------------------- /.history/README_20250309062815.md: -------------------------------------------------------------------------------- 1 | # SiliconFlow自动填写手机号脚本 2 | 3 | 这个Python脚本可以自动打开SiliconFlow的登录页面并填写手机号码。支持同时打开多个浏览器实例,并允许用户在运行时输入手机号。 4 | 5 | ## 安装依赖 6 | 7 | 在使用脚本之前,请确保安装所有必要的依赖: 8 | 9 | ```bash 10 | pip install -r requirements.txt 11 | ``` 12 | 13 | ## 使用方法 14 | 15 | ### 交互式输入模式(当前模式) 16 | 1. 运行脚本: 17 | ```bash 18 | python auto_phone_fill.py 19 | ``` 20 | 2. 按照提示输入需要开启的浏览器数量(1-10) 21 | 3. 依次输入每个浏览器实例要填写的手机号码 22 | 4. 确认输入的手机号无误后,脚本将自动打开浏览器并填写手机号 23 | 24 | ### 旧版使用方法(已弃用) 25 | ~~1. 打开`auto_phone_fill.py`文件~~ 26 | ~~2. 在文件底部找到`phone_numbers`列表,替换为您想要填写的手机号码~~ 27 | ~~3. 运行脚本~~ 28 | 29 | ## 注意事项 30 | 31 | - 脚本默认会打开Chrome浏览器窗口,如需以无头模式运行(不显示浏览器窗口),请修改源代码中的相关设置 32 | - 脚本执行后浏览器默认不会自动关闭,以便您查看结果或继续操作 33 | - 网页元素定位可能会因网站变更而失效,如遇问题请根据错误信息调整XPATH选择器 34 | - 在多浏览器模式下,脚本会依次启动浏览器并填写相应的手机号码,每个浏览器之间有1秒的延迟以避免资源竞争 35 | - 输入手机号时会进行简单的格式验证,确保输入的是11位数字 -------------------------------------------------------------------------------- /.history/README_20250309063402.md: -------------------------------------------------------------------------------- 1 | # SiliconFlow自动填写手机号脚本 2 | 3 | 这个Python脚本可以自动打开SiliconFlow的登录页面并填写手机号码。支持同时打开多个浏览器实例,并允许用户在运行时输入手机号。 4 | 5 | ## 安装依赖 6 | 7 | 在使用脚本之前,请确保安装所有必要的依赖: 8 | 9 | ```bash 10 | pip install -r requirements.txt 11 | ``` 12 | 13 | ## 使用方法 14 | 15 | ### 交互式输入模式(当前模式) 16 | 1. 运行脚本: 17 | ```bash 18 | python auto_phone_fill.py 19 | ``` 20 | 2. 按照提示输入需要开启的浏览器数量(1-10) 21 | 3. 依次输入每个浏览器实例要填写的手机号码 22 | 4. 输入完成后,脚本将自动打开多个浏览器并填写相应的手机号 23 | 24 | ### 旧版使用方法(已弃用) 25 | ~~1. 打开`auto_phone_fill.py`文件~~ 26 | ~~2. 在文件底部找到`phone_numbers`列表,替换为您想要填写的手机号码~~ 27 | ~~3. 运行脚本~~ 28 | 29 | ## 注意事项 30 | 31 | - 脚本默认会打开Chrome浏览器窗口,如需以无头模式运行(不显示浏览器窗口),请修改源代码中的相关设置 32 | - 脚本执行后浏览器默认不会自动关闭,保持打开状态供您继续操作 33 | - 网页元素定位可能会因网站变更而失效,如遇问题请根据错误信息调整XPATH选择器 34 | - 在多浏览器模式下,脚本会依次启动浏览器并填写相应的手机号码,每个浏览器之间有1秒的延迟以避免资源竞争 35 | - 输入手机号时会进行简单的格式验证,确保输入的是11位数字 -------------------------------------------------------------------------------- /.history/README_20250309063803.md: -------------------------------------------------------------------------------- 1 | # SiliconFlow自动填写手机号脚本 2 | 3 | 这个Python脚本可以自动打开SiliconFlow的登录页面并填写手机号码。支持同时打开多个浏览器实例,并允许用户在运行时输入手机号。 4 | 5 | ## 安装依赖 6 | 7 | 在使用脚本之前,请确保安装所有必要的依赖: 8 | 9 | ```bash 10 | pip install -r requirements.txt 11 | ``` 12 | 13 | ## 使用方法 14 | 15 | ### 交互式输入模式(当前模式) 16 | 1. 运行脚本: 17 | ```bash 18 | python auto_phone_fill.py 19 | ``` 20 | 2. 按照提示输入需要开启的浏览器数量(1-10) 21 | 3. 依次输入每个浏览器实例要填写的手机号码 22 | 4. 输入完成后,脚本将自动打开多个浏览器并填写相应的手机号 23 | 5. 脚本会保持运行状态以确保浏览器不会关闭 24 | 6. 当您完成所有操作后,按下Ctrl+C终止脚本(浏览器会保持打开状态) 25 | 26 | ### 旧版使用方法(已弃用) 27 | ~~1. 打开`auto_phone_fill.py`文件~~ 28 | ~~2. 在文件底部找到`phone_numbers`列表,替换为您想要填写的手机号码~~ 29 | ~~3. 运行脚本~~ 30 | 31 | ## 注意事项 32 | 33 | - 脚本默认会打开Chrome浏览器窗口,如需以无头模式运行(不显示浏览器窗口),请修改源代码中的相关设置 34 | - 浏览器会一直保持打开状态,即使在脚本终止后也不会关闭,您可以手动关闭浏览器窗口 35 | - 如果您想要终止脚本但保持浏览器窗口打开,只需按Ctrl+C即可 36 | - 网页元素定位可能会因网站变更而失效,如遇问题请根据错误信息调整XPATH选择器 37 | - 在多浏览器模式下,脚本会依次启动浏览器并填写相应的手机号码,每个浏览器之间有1秒的延迟以避免资源竞争 38 | - 输入手机号时会进行简单的格式验证,确保输入的是11位数字 -------------------------------------------------------------------------------- /.history/README_20250309064404.md: -------------------------------------------------------------------------------- 1 | # SiliconFlow自动填写手机号脚本 2 | 3 | 这个Python脚本可以自动打开SiliconFlow的登录页面并填写手机号码。支持同时打开多个浏览器实例,并允许用户在运行时输入手机号。脚本采用了先进的技术来模拟真实用户行为,有效绕过自动化检测。 4 | 5 | ## 安装依赖 6 | 7 | 在使用脚本之前,请确保安装所有必要的依赖: 8 | 9 | ```bash 10 | pip install -r requirements.txt 11 | ``` 12 | 13 | ## 使用方法 14 | 15 | ### 交互式输入模式(当前模式) 16 | 1. 运行脚本: 17 | ```bash 18 | python auto_phone_fill.py 19 | ``` 20 | 2. 按照提示输入需要开启的浏览器数量(1-10) 21 | 3. 依次输入每个浏览器实例要填写的手机号码 22 | 4. 输入完成后,脚本将自动打开多个浏览器并填写相应的手机号 23 | 5. 脚本会保持运行状态以确保浏览器不会关闭 24 | 6. 当您完成所有操作后,按下Ctrl+C终止脚本(浏览器会保持打开状态) 25 | 26 | ### 旧版使用方法(已弃用) 27 | ~~1. 打开`auto_phone_fill.py`文件~~ 28 | ~~2. 在文件底部找到`phone_numbers`列表,替换为您想要填写的手机号码~~ 29 | ~~3. 运行脚本~~ 30 | 31 | ## 注意事项 32 | 33 | - 脚本默认会打开Chrome浏览器窗口,如需以无头模式运行(不显示浏览器窗口),请修改源代码中的相关设置 34 | - 浏览器会一直保持打开状态,即使在脚本终止后也不会关闭,您可以手动关闭浏览器窗口 35 | - 如果您想要终止脚本但保持浏览器窗口打开,只需按Ctrl+C即可 36 | - 网页元素定位可能会因网站变更而失效,如遇问题请根据错误信息调整XPATH选择器 37 | - 在多浏览器模式下,脚本会依次启动浏览器并填写相应的手机号码,每个浏览器之间有随机延迟以避免资源竞争 38 | - 输入手机号时会进行简单的格式验证,确保输入的是11位数字 39 | 40 | ## 反检测特性 41 | 42 | 该脚本已实现多种反检测机制,有效绕过大多数网站的自动化检测: 43 | 44 | - 模拟真实人类的输入行为(随机打字速度和暂停) 45 | - 随机鼠标移动轨迹 46 | - 随机浏览器窗口大小 47 | - 随机用户代理(User-Agent) 48 | - 修改浏览器特征,隐藏自动化标记 49 | - 自然的操作时间间隔 50 | - 逼真的浏览交互模式(点击、移动、暂停等) -------------------------------------------------------------------------------- /.history/README_20250309070210.md: -------------------------------------------------------------------------------- 1 | # SiliconFlow自动填写手机号脚本 2 | 3 | 这个Python脚本可以自动打开SiliconFlow的登录页面并填写手机号码。支持同时打开多个浏览器实例,并允许用户在运行时输入手机号。脚本采用了最先进的反检测技术,包括使用专业的undetected_chromedriver库,有效绕过网站的自动化检测。 4 | 5 | ## 安装依赖 6 | 7 | 在使用脚本之前,请确保安装所有必要的依赖: 8 | 9 | ```bash 10 | pip install -r requirements.txt 11 | ``` 12 | 13 | ## 使用方法 14 | 15 | ### 交互式输入模式(当前模式) 16 | 1. 运行脚本: 17 | ```bash 18 | python auto_phone_fill.py 19 | ``` 20 | 2. 按照提示输入需要开启的浏览器数量(1-10) 21 | 3. 依次输入每个浏览器实例要填写的手机号码 22 | 4. 输入完成后,脚本将自动打开多个浏览器并填写相应的手机号 23 | 5. 脚本会保持运行状态以确保浏览器不会关闭 24 | 6. 当您完成所有操作后,按下Ctrl+C终止脚本(浏览器会保持打开状态) 25 | 26 | ### 旧版使用方法(已弃用) 27 | ~~1. 打开`auto_phone_fill.py`文件~~ 28 | ~~2. 在文件底部找到`phone_numbers`列表,替换为您想要填写的手机号码~~ 29 | ~~3. 运行脚本~~ 30 | 31 | ## 注意事项 32 | 33 | - 脚本默认会打开Chrome浏览器窗口,如需以无头模式运行(不显示浏览器窗口),请修改源代码中的相关设置 34 | - 浏览器会一直保持打开状态,即使在脚本终止后也不会关闭,您可以手动关闭浏览器窗口 35 | - 如果您想要终止脚本但保持浏览器窗口打开,只需按Ctrl+C即可 36 | - 网页元素定位可能会因网站变更而失效,如遇问题请根据错误信息调整XPATH选择器 37 | - 在多浏览器模式下,脚本会依次启动浏览器并填写相应的手机号码,每个浏览器之间有随机延迟以避免资源竞争 38 | - 输入手机号时会进行简单的格式验证,确保输入的是11位数字 39 | - 每个浏览器实例都会使用独立的用户数据目录,这有助于避免会话冲突和指纹追踪 40 | 41 | ## 高级反检测技术 42 | 43 | 该脚本使用了多种专业级反检测技术,有效绕过大多数网站的自动化检测: 44 | 45 | - 使用专业的`undetected_chromedriver`库代替标准Selenium(最重要的改进) 46 | - 为每个浏览器实例创建独立的用户数据目录,隔离会话状态 47 | - 使用隐身模式(Incognito)增强隐私和减少指纹 48 | - 模拟真实人类的输入行为(随机打字速度和暂停) 49 | - 模拟网页滚动和鼠标移动 50 | - 多重选择器策略,提高元素定位成功率 51 | - 随机浏览器窗口大小 52 | - 随机用户代理(User-Agent) 53 | - 禁用自动化控制特征 54 | - 自然的操作时间间隔 55 | - 随机化交互行为(Tab键或悬停在验证码按钮上) -------------------------------------------------------------------------------- /.history/README_20250309070942.md: -------------------------------------------------------------------------------- 1 | # SiliconFlow自动填写手机号脚本 2 | 3 | 这个Python脚本可以自动打开SiliconFlow的登录页面并填写手机号码。支持同时打开多个浏览器实例,并允许用户在运行时输入手机号。脚本采用了最先进的反检测技术,包括使用专业的undetected_chromedriver库,有效绕过网站的自动化检测。 4 | 5 | ## 安装依赖 6 | 7 | 在使用脚本之前,请确保安装所有必要的依赖: 8 | 9 | ```bash 10 | pip install -r requirements.txt 11 | ``` 12 | 13 | ## 使用方法 14 | 15 | ### 交互式输入模式(当前模式) 16 | 1. 运行脚本: 17 | ```bash 18 | python auto_phone_fill.py 19 | ``` 20 | 2. 按照提示输入需要开启的浏览器数量(1-10) 21 | 3. 依次输入每个浏览器实例要填写的手机号码 22 | 4. 输入完成后,脚本将自动打开多个浏览器并填写相应的手机号 23 | 5. 脚本会保持运行状态以确保浏览器不会关闭 24 | 6. 当您完成所有操作后,按下Ctrl+C终止脚本(浏览器会保持打开状态) 25 | 26 | ### 旧版使用方法(已弃用) 27 | ~~1. 打开`auto_phone_fill.py`文件~~ 28 | ~~2. 在文件底部找到`phone_numbers`列表,替换为您想要填写的手机号码~~ 29 | ~~3. 运行脚本~~ 30 | 31 | ## 注意事项 32 | 33 | - 脚本默认会打开Chrome浏览器窗口,如需以无头模式运行(不显示浏览器窗口),请修改源代码中的相关设置 34 | - 浏览器会一直保持打开状态,即使在脚本终止后也不会关闭,您可以手动关闭浏览器窗口 35 | - 如果您想要终止脚本但保持浏览器窗口打开,只需按Ctrl+C即可 36 | - 网页元素定位可能会因网站变更而失效,如遇问题请根据错误信息调整XPATH选择器 37 | - 在多浏览器模式下,脚本会依次启动浏览器并填写相应的手机号码,每个浏览器之间有随机延迟以避免资源竞争 38 | - 输入手机号时会进行简单的格式验证,确保输入的是11位数字 39 | - 每个浏览器实例都会使用独立的用户数据目录,这有助于避免会话冲突和指纹追踪 40 | 41 | ## 高级反检测技术 42 | 43 | 该脚本使用了多种专业级反检测技术,有效绕过大多数网站的自动化检测: 44 | 45 | - 使用专业的`undetected_chromedriver`库代替标准Selenium(最重要的改进) 46 | - 为每个浏览器实例创建独立的用户数据目录,隔离会话状态 47 | - 使用隐身模式(Incognito)增强隐私和减少指纹 48 | - 直接输入手机号(不再模拟逐字符输入) 49 | - 多重选择器策略,提高元素定位成功率 50 | - 随机浏览器窗口大小 51 | - 随机用户代理(User-Agent) 52 | - 禁用自动化控制特征 53 | - 使用Chrome 133版本的驱动程序,匹配当前浏览器版本 -------------------------------------------------------------------------------- /.history/README_20250309071334.md: -------------------------------------------------------------------------------- 1 | # SiliconFlow自动填写手机号脚本 2 | 3 | 这个Python脚本可以自动打开SiliconFlow的登录页面并填写手机号码。支持同时打开多个浏览器实例,并能自动从文本中提取手机号。脚本采用了最先进的反检测技术,包括使用专业的undetected_chromedriver库,有效绕过网站的自动化检测。 4 | 5 | ## 安装依赖 6 | 7 | 在使用脚本之前,请确保安装所有必要的依赖: 8 | 9 | ```bash 10 | pip install -r requirements.txt 11 | ``` 12 | 13 | ## 使用方法 14 | 15 | ### 批量提取模式(当前模式) 16 | 1. 运行脚本: 17 | ```bash 18 | python auto_phone_fill.py 19 | ``` 20 | 2. 脚本会提示您粘贴包含手机号的文本(可以是任意格式的文本,如聊天记录、文档等) 21 | 3. 粘贴文本后,按两次回车确认输入完成 22 | 4. 脚本会自动提取文本中的所有手机号 23 | 5. 确认提取到的手机号后,脚本会自动启动相应数量的浏览器并填写手机号 24 | 6. 脚本会保持运行状态以确保浏览器不会关闭 25 | 7. 当您完成所有操作后,按下Ctrl+C终止脚本(浏览器会保持打开状态) 26 | 27 | ### 旧版使用方法(已弃用) 28 | ~~1. 交互式输入手机号~~ 29 | ~~2. 在文件中预设手机号列表~~ 30 | 31 | ## 注意事项 32 | 33 | - 脚本默认会打开Chrome浏览器窗口,如需以无头模式运行(不显示浏览器窗口),请修改源代码中的相关设置 34 | - 浏览器会一直保持打开状态,即使在脚本终止后也不会关闭,您可以手动关闭浏览器窗口 35 | - 如果您想要终止脚本但保持浏览器窗口打开,只需按Ctrl+C即可 36 | - 网页元素定位可能会因网站变更而失效,如遇问题请根据错误信息调整XPATH选择器 37 | - 在多浏览器模式下,脚本会依次启动浏览器并填写相应的手机号码,每个浏览器之间有随机延迟以避免资源竞争 38 | - 提取手机号时使用正则表达式模式`1[3-9]\d{9}`,符合中国大陆手机号格式 39 | - 脚本会自动去除重复的手机号,每个手机号只会开启一个浏览器实例 40 | - 每个浏览器实例都会使用独立的用户数据目录,这有助于避免会话冲突和指纹追踪 41 | 42 | ## 高级反检测技术 43 | 44 | 该脚本使用了多种专业级反检测技术,有效绕过大多数网站的自动化检测: 45 | 46 | - 使用专业的`undetected_chromedriver`库代替标准Selenium(最重要的改进) 47 | - 为每个浏览器实例创建独立的用户数据目录,隔离会话状态 48 | - 使用隐身模式(Incognito)增强隐私和减少指纹 49 | - 直接输入手机号(不再模拟逐字符输入) 50 | - 多重选择器策略,提高元素定位成功率 51 | - 随机浏览器窗口大小 52 | - 随机用户代理(User-Agent) 53 | - 禁用自动化控制特征 54 | - 使用Chrome 133版本的驱动程序,匹配当前浏览器版本 -------------------------------------------------------------------------------- /.history/auto_phone_fill_20250309061744.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.history/auto_phone_fill_20250309061747.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | from selenium.webdriver.support.ui import WebDriverWait 4 | from selenium.webdriver.support import expected_conditions as EC 5 | from selenium.webdriver.chrome.service import Service 6 | from webdriver_manager.chrome import ChromeDriverManager 7 | import time 8 | 9 | def auto_fill_phone(phone_number): 10 | """ 11 | 自动打开SiliconFlow登录页面并填写手机号 12 | 13 | 参数: 14 | phone_number (str): 要填写的手机号码 15 | """ 16 | print(f"开始为手机号 {phone_number} 自动填写表单...") 17 | 18 | # 初始化Chrome浏览器 19 | options = webdriver.ChromeOptions() 20 | # options.add_argument('--headless') # 无头模式,取消注释可不显示浏览器窗口 21 | 22 | # 初始化WebDriver 23 | driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options) 24 | 25 | try: 26 | # 打开登录页面 27 | url = "https://account.siliconflow.cn/zh/login?redirect=https%3A%2F%2Fcloud.siliconflow.cn%2F%3F" 28 | driver.get(url) 29 | print("已打开登录页面") 30 | 31 | # 等待页面加载 32 | time.sleep(2) 33 | 34 | # 找到手机号输入框并填写 35 | # 这里需要根据实际网页元素定位手机号输入框 36 | # 可能的选择器包括:id、name、class name、XPath等 37 | # 下面是一些常见的选择方法,可能需要调整 38 | try: 39 | # 尝试通过placeholder找到输入框 40 | phone_input = WebDriverWait(driver, 10).until( 41 | EC.presence_of_element_located((By.XPATH, "//input[@placeholder='请输入手机号' or contains(@placeholder, '手机号')]")) 42 | ) 43 | phone_input.clear() 44 | phone_input.send_keys(phone_number) 45 | print(f"已成功填写手机号: {phone_number}") 46 | 47 | # 等待一段时间以便查看结果 48 | time.sleep(5) 49 | 50 | except Exception as e: 51 | print(f"填写手机号时出错: {e}") 52 | 53 | # 如果上面的方法失败,可以尝试打印页面源代码帮助调试 54 | print("页面源代码:") 55 | print(driver.page_source) 56 | 57 | finally: 58 | # 关闭浏览器 59 | # 注释掉下一行可以保持浏览器打开以便查看结果 60 | # driver.quit() 61 | print("脚本执行完毕") 62 | 63 | if __name__ == "__main__": 64 | # 在这里输入您想要填写的手机号 65 | phone_number = "13800138000" # 替换成您想要填写的手机号 66 | auto_fill_phone(phone_number) -------------------------------------------------------------------------------- /.history/auto_phone_fill_20250309061808.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | from selenium.webdriver.support.ui import WebDriverWait 4 | from selenium.webdriver.support import expected_conditions as EC 5 | from selenium.webdriver.chrome.service import Service 6 | from webdriver_manager.chrome import ChromeDriverManager 7 | import time 8 | 9 | def auto_fill_phone(phone_number): 10 | """ 11 | 自动打开SiliconFlow登录页面并填写手机号 12 | 13 | 参数: 14 | phone_number (str): 要填写的手机号码 15 | """ 16 | print(f"开始为手机号 {phone_number} 自动填写表单...") 17 | 18 | # 初始化Chrome浏览器 19 | options = webdriver.ChromeOptions() 20 | # options.add_argument('--headless') # 无头模式,取消注释可不显示浏览器窗口 21 | 22 | # 初始化WebDriver 23 | driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options) 24 | 25 | try: 26 | # 打开登录页面 27 | url = "https://account.siliconflow.cn/zh/login?redirect=https%3A%2F%2Fcloud.siliconflow.cn%2F%3F" 28 | driver.get(url) 29 | print("已打开登录页面") 30 | 31 | # 等待页面加载 32 | time.sleep(2) 33 | 34 | # 找到手机号输入框并填写 35 | # 这里需要根据实际网页元素定位手机号输入框 36 | # 可能的选择器包括:id、name、class name、XPath等 37 | # 下面是一些常见的选择方法,可能需要调整 38 | try: 39 | # 尝试通过placeholder找到输入框 40 | phone_input = WebDriverWait(driver, 10).until( 41 | EC.presence_of_element_located((By.XPATH, "//input[@placeholder='请输入手机号' or contains(@placeholder, '手机号')]")) 42 | ) 43 | phone_input.clear() 44 | phone_input.send_keys(phone_number) 45 | print(f"已成功填写手机号: {phone_number}") 46 | 47 | # 等待一段时间以便查看结果 48 | time.sleep(5) 49 | 50 | except Exception as e: 51 | print(f"填写手机号时出错: {e}") 52 | 53 | # 如果上面的方法失败,可以尝试打印页面源代码帮助调试 54 | print("页面源代码:") 55 | print(driver.page_source) 56 | 57 | finally: 58 | # 关闭浏览器 59 | # 注释掉下一行可以保持浏览器打开以便查看结果 60 | # driver.quit() 61 | print("脚本执行完毕") 62 | 63 | if __name__ == "__main__": 64 | # 在这里输入您想要填写的手机号 65 | phone_number = "13800138000" # 替换成您想要填写的手机号 66 | auto_fill_phone(phone_number) -------------------------------------------------------------------------------- /.history/auto_phone_fill_20250309062452.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | from selenium.webdriver.support.ui import WebDriverWait 4 | from selenium.webdriver.support import expected_conditions as EC 5 | from selenium.webdriver.chrome.service import Service 6 | from webdriver_manager.chrome import ChromeDriverManager 7 | import time 8 | import threading 9 | 10 | def auto_fill_phone(phone_number): 11 | """ 12 | 自动打开SiliconFlow登录页面并填写手机号 13 | 14 | 参数: 15 | phone_number (str): 要填写的手机号码 16 | """ 17 | print(f"开始为手机号 {phone_number} 自动填写表单...") 18 | 19 | # 初始化Chrome浏览器 20 | options = webdriver.ChromeOptions() 21 | # options.add_argument('--headless') # 无头模式,取消注释可不显示浏览器窗口 22 | 23 | # 初始化WebDriver 24 | driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options) 25 | 26 | try: 27 | # 打开登录页面 28 | url = "https://account.siliconflow.cn/zh/login?redirect=https%3A%2F%2Fcloud.siliconflow.cn%2F%3F" 29 | driver.get(url) 30 | print(f"已为手机号 {phone_number} 打开登录页面") 31 | 32 | # 等待页面加载 33 | time.sleep(2) 34 | 35 | # 找到手机号输入框并填写 36 | # 这里需要根据实际网页元素定位手机号输入框 37 | # 可能的选择器包括:id、name、class name、XPath等 38 | # 下面是一些常见的选择方法,可能需要调整 39 | try: 40 | # 尝试通过placeholder找到输入框 41 | phone_input = WebDriverWait(driver, 10).until( 42 | EC.presence_of_element_located((By.XPATH, "//input[@placeholder='请输入手机号' or contains(@placeholder, '手机号')]")) 43 | ) 44 | phone_input.clear() 45 | phone_input.send_keys(phone_number) 46 | print(f"已成功填写手机号: {phone_number}") 47 | 48 | # 等待一段时间以便查看结果 49 | time.sleep(5) 50 | 51 | except Exception as e: 52 | print(f"填写手机号时出错: {e}") 53 | 54 | # 如果上面的方法失败,可以尝试打印页面源代码帮助调试 55 | print("页面源代码:") 56 | print(driver.page_source) 57 | 58 | finally: 59 | # 关闭浏览器 60 | # 注释掉下一行可以保持浏览器打开以便查看结果 61 | # driver.quit() 62 | print(f"手机号 {phone_number} 脚本执行完毕") 63 | 64 | def open_multiple_browsers(phone_numbers): 65 | """ 66 | 同时打开多个浏览器实例并填写不同的手机号 67 | 68 | 参数: 69 | phone_numbers (list): 要填写的手机号列表 70 | """ 71 | threads = [] 72 | 73 | # 为每个手机号创建一个线程 74 | for phone in phone_numbers: 75 | thread = threading.Thread(target=auto_fill_phone, args=(phone,)) 76 | threads.append(thread) 77 | 78 | # 启动所有线程 79 | for thread in threads: 80 | thread.start() 81 | # 等待一小段时间,避免同时启动多个浏览器导致资源竞争 82 | time.sleep(1) 83 | 84 | # 等待所有线程完成 85 | for thread in threads: 86 | thread.join() 87 | 88 | print("所有浏览器实例已启动完毕") 89 | 90 | if __name__ == "__main__": 91 | # 在这里输入您想要填写的手机号列表 92 | phone_numbers = [ 93 | "13800138001", # 第一个浏览器填写的手机号 94 | "13800138002", # 第二个浏览器填写的手机号 95 | "13800138003", # 第三个浏览器填写的手机号 96 | ] 97 | 98 | # 同时打开3个浏览器 99 | open_multiple_browsers(phone_numbers) -------------------------------------------------------------------------------- /.history/auto_phone_fill_20250309062459.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | from selenium.webdriver.support.ui import WebDriverWait 4 | from selenium.webdriver.support import expected_conditions as EC 5 | from selenium.webdriver.chrome.service import Service 6 | from webdriver_manager.chrome import ChromeDriverManager 7 | import time 8 | import threading 9 | 10 | def auto_fill_phone(phone_number): 11 | """ 12 | 自动打开SiliconFlow登录页面并填写手机号 13 | 14 | 参数: 15 | phone_number (str): 要填写的手机号码 16 | """ 17 | print(f"开始为手机号 {phone_number} 自动填写表单...") 18 | 19 | # 初始化Chrome浏览器 20 | options = webdriver.ChromeOptions() 21 | # options.add_argument('--headless') # 无头模式,取消注释可不显示浏览器窗口 22 | 23 | # 初始化WebDriver 24 | driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options) 25 | 26 | try: 27 | # 打开登录页面 28 | url = "https://account.siliconflow.cn/zh/login?redirect=https%3A%2F%2Fcloud.siliconflow.cn%2F%3F" 29 | driver.get(url) 30 | print(f"已为手机号 {phone_number} 打开登录页面") 31 | 32 | # 等待页面加载 33 | time.sleep(2) 34 | 35 | # 找到手机号输入框并填写 36 | # 这里需要根据实际网页元素定位手机号输入框 37 | # 可能的选择器包括:id、name、class name、XPath等 38 | # 下面是一些常见的选择方法,可能需要调整 39 | try: 40 | # 尝试通过placeholder找到输入框 41 | phone_input = WebDriverWait(driver, 10).until( 42 | EC.presence_of_element_located((By.XPATH, "//input[@placeholder='请输入手机号' or contains(@placeholder, '手机号')]")) 43 | ) 44 | phone_input.clear() 45 | phone_input.send_keys(phone_number) 46 | print(f"已成功填写手机号: {phone_number}") 47 | 48 | # 等待一段时间以便查看结果 49 | time.sleep(5) 50 | 51 | except Exception as e: 52 | print(f"填写手机号时出错: {e}") 53 | 54 | # 如果上面的方法失败,可以尝试打印页面源代码帮助调试 55 | print("页面源代码:") 56 | print(driver.page_source) 57 | 58 | finally: 59 | # 关闭浏览器 60 | # 注释掉下一行可以保持浏览器打开以便查看结果 61 | # driver.quit() 62 | print(f"手机号 {phone_number} 脚本执行完毕") 63 | 64 | def open_multiple_browsers(phone_numbers): 65 | """ 66 | 同时打开多个浏览器实例并填写不同的手机号 67 | 68 | 参数: 69 | phone_numbers (list): 要填写的手机号列表 70 | """ 71 | threads = [] 72 | 73 | # 为每个手机号创建一个线程 74 | for phone in phone_numbers: 75 | thread = threading.Thread(target=auto_fill_phone, args=(phone,)) 76 | threads.append(thread) 77 | 78 | # 启动所有线程 79 | for thread in threads: 80 | thread.start() 81 | # 等待一小段时间,避免同时启动多个浏览器导致资源竞争 82 | time.sleep(1) 83 | 84 | # 等待所有线程完成 85 | for thread in threads: 86 | thread.join() 87 | 88 | print("所有浏览器实例已启动完毕") 89 | 90 | if __name__ == "__main__": 91 | # 在这里输入您想要填写的手机号列表 92 | phone_numbers = [ 93 | "13800138001", # 第一个浏览器填写的手机号 94 | "13800138002", # 第二个浏览器填写的手机号 95 | "13800138003", # 第三个浏览器填写的手机号 96 | ] 97 | 98 | # 同时打开3个浏览器 99 | open_multiple_browsers(phone_numbers) -------------------------------------------------------------------------------- /.history/auto_phone_fill_20250309062759.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | from selenium.webdriver.support.ui import WebDriverWait 4 | from selenium.webdriver.support import expected_conditions as EC 5 | from selenium.webdriver.chrome.service import Service 6 | from webdriver_manager.chrome import ChromeDriverManager 7 | import time 8 | import threading 9 | 10 | def auto_fill_phone(phone_number): 11 | """ 12 | 自动打开SiliconFlow登录页面并填写手机号 13 | 14 | 参数: 15 | phone_number (str): 要填写的手机号码 16 | """ 17 | print(f"开始为手机号 {phone_number} 自动填写表单...") 18 | 19 | # 初始化Chrome浏览器 20 | options = webdriver.ChromeOptions() 21 | # options.add_argument('--headless') # 无头模式,取消注释可不显示浏览器窗口 22 | 23 | # 初始化WebDriver 24 | driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options) 25 | 26 | try: 27 | # 打开登录页面 28 | url = "https://account.siliconflow.cn/zh/login?redirect=https%3A%2F%2Fcloud.siliconflow.cn%2F%3F" 29 | driver.get(url) 30 | print(f"已为手机号 {phone_number} 打开登录页面") 31 | 32 | # 等待页面加载 33 | time.sleep(2) 34 | 35 | # 找到手机号输入框并填写 36 | # 这里需要根据实际网页元素定位手机号输入框 37 | # 可能的选择器包括:id、name、class name、XPath等 38 | # 下面是一些常见的选择方法,可能需要调整 39 | try: 40 | # 尝试通过placeholder找到输入框 41 | phone_input = WebDriverWait(driver, 10).until( 42 | EC.presence_of_element_located((By.XPATH, "//input[@placeholder='请输入手机号' or contains(@placeholder, '手机号')]")) 43 | ) 44 | phone_input.clear() 45 | phone_input.send_keys(phone_number) 46 | print(f"已成功填写手机号: {phone_number}") 47 | 48 | # 等待一段时间以便查看结果 49 | time.sleep(5) 50 | 51 | except Exception as e: 52 | print(f"填写手机号时出错: {e}") 53 | 54 | # 如果上面的方法失败,可以尝试打印页面源代码帮助调试 55 | print("页面源代码:") 56 | print(driver.page_source) 57 | 58 | finally: 59 | # 关闭浏览器 60 | # 注释掉下一行可以保持浏览器打开以便查看结果 61 | # driver.quit() 62 | print(f"手机号 {phone_number} 脚本执行完毕") 63 | 64 | def open_multiple_browsers(phone_numbers): 65 | """ 66 | 同时打开多个浏览器实例并填写不同的手机号 67 | 68 | 参数: 69 | phone_numbers (list): 要填写的手机号列表 70 | """ 71 | threads = [] 72 | 73 | # 为每个手机号创建一个线程 74 | for phone in phone_numbers: 75 | thread = threading.Thread(target=auto_fill_phone, args=(phone,)) 76 | threads.append(thread) 77 | 78 | # 启动所有线程 79 | for thread in threads: 80 | thread.start() 81 | # 等待一小段时间,避免同时启动多个浏览器导致资源竞争 82 | time.sleep(1) 83 | 84 | # 等待所有线程完成 85 | for thread in threads: 86 | thread.join() 87 | 88 | print("所有浏览器实例已启动完毕") 89 | 90 | def get_user_input_phones(browser_count): 91 | """ 92 | 获取用户输入的手机号 93 | 94 | 参数: 95 | browser_count (int): 需要开启的浏览器数量 96 | 97 | 返回: 98 | list: 用户输入的手机号列表 99 | """ 100 | phone_numbers = [] 101 | print(f"\n请输入{browser_count}个手机号,每个手机号输入完成后按回车确认:") 102 | 103 | for i in range(browser_count): 104 | while True: 105 | phone = input(f"请输入第 {i+1} 个手机号: ") 106 | 107 | # 简单验证手机号格式(11位数字) 108 | if phone.isdigit() and len(phone) == 11: 109 | phone_numbers.append(phone) 110 | break 111 | else: 112 | print("手机号格式不正确,请输入11位数字手机号!") 113 | 114 | # 确认输入的手机号 115 | print("\n您输入的手机号如下:") 116 | for i, phone in enumerate(phone_numbers): 117 | print(f"{i+1}. {phone}") 118 | 119 | confirm = input("\n确认使用这些手机号?(y/n): ") 120 | if confirm.lower() != 'y': 121 | print("已取消操作,请重新运行脚本!") 122 | return [] 123 | 124 | return phone_numbers 125 | 126 | if __name__ == "__main__": 127 | # 获取用户输入的浏览器数量 128 | while True: 129 | try: 130 | browser_count = int(input("请输入需要开启的浏览器数量(1-10): ")) 131 | if 1 <= browser_count <= 10: 132 | break 133 | else: 134 | print("请输入1到10之间的数字!") 135 | except ValueError: 136 | print("请输入有效的数字!") 137 | 138 | # 获取用户输入的手机号 139 | phone_numbers = get_user_input_phones(browser_count) 140 | 141 | if phone_numbers: 142 | # 同时打开多个浏览器 143 | open_multiple_browsers(phone_numbers) 144 | else: 145 | print("未输入有效的手机号,脚本已退出。") -------------------------------------------------------------------------------- /.history/auto_phone_fill_20250309062921.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | from selenium.webdriver.support.ui import WebDriverWait 4 | from selenium.webdriver.support import expected_conditions as EC 5 | from selenium.webdriver.chrome.service import Service 6 | from webdriver_manager.chrome import ChromeDriverManager 7 | import time 8 | import threading 9 | 10 | def auto_fill_phone(phone_number): 11 | """ 12 | 自动打开SiliconFlow登录页面并填写手机号 13 | 14 | 参数: 15 | phone_number (str): 要填写的手机号码 16 | """ 17 | print(f"开始为手机号 {phone_number} 自动填写表单...") 18 | 19 | # 初始化Chrome浏览器 20 | options = webdriver.ChromeOptions() 21 | # options.add_argument('--headless') # 无头模式,取消注释可不显示浏览器窗口 22 | 23 | # 初始化WebDriver 24 | driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options) 25 | 26 | try: 27 | # 打开登录页面 28 | url = "https://account.siliconflow.cn/zh/login?redirect=https%3A%2F%2Fcloud.siliconflow.cn%2F%3F" 29 | driver.get(url) 30 | print(f"已为手机号 {phone_number} 打开登录页面") 31 | 32 | # 等待页面加载 33 | time.sleep(2) 34 | 35 | # 找到手机号输入框并填写 36 | # 这里需要根据实际网页元素定位手机号输入框 37 | # 可能的选择器包括:id、name、class name、XPath等 38 | # 下面是一些常见的选择方法,可能需要调整 39 | try: 40 | # 尝试通过placeholder找到输入框 41 | phone_input = WebDriverWait(driver, 10).until( 42 | EC.presence_of_element_located((By.XPATH, "//input[@placeholder='请输入手机号' or contains(@placeholder, '手机号')]")) 43 | ) 44 | phone_input.clear() 45 | phone_input.send_keys(phone_number) 46 | print(f"已成功填写手机号: {phone_number}") 47 | 48 | # 等待一段时间以便查看结果 49 | time.sleep(5) 50 | 51 | except Exception as e: 52 | print(f"填写手机号时出错: {e}") 53 | 54 | # 如果上面的方法失败,可以尝试打印页面源代码帮助调试 55 | print("页面源代码:") 56 | print(driver.page_source) 57 | 58 | finally: 59 | # 关闭浏览器 60 | # 注释掉下一行可以保持浏览器打开以便查看结果 61 | # driver.quit() 62 | print(f"手机号 {phone_number} 脚本执行完毕") 63 | 64 | def open_multiple_browsers(phone_numbers): 65 | """ 66 | 同时打开多个浏览器实例并填写不同的手机号 67 | 68 | 参数: 69 | phone_numbers (list): 要填写的手机号列表 70 | """ 71 | threads = [] 72 | 73 | # 为每个手机号创建一个线程 74 | for phone in phone_numbers: 75 | thread = threading.Thread(target=auto_fill_phone, args=(phone,)) 76 | threads.append(thread) 77 | 78 | # 启动所有线程 79 | for thread in threads: 80 | thread.start() 81 | # 等待一小段时间,避免同时启动多个浏览器导致资源竞争 82 | time.sleep(1) 83 | 84 | # 等待所有线程完成 85 | for thread in threads: 86 | thread.join() 87 | 88 | print("所有浏览器实例已启动完毕") 89 | 90 | def get_user_input_phones(browser_count): 91 | """ 92 | 获取用户输入的手机号 93 | 94 | 参数: 95 | browser_count (int): 需要开启的浏览器数量 96 | 97 | 返回: 98 | list: 用户输入的手机号列表 99 | """ 100 | phone_numbers = [] 101 | print(f"\n请输入{browser_count}个手机号,每个手机号输入完成后按回车确认:") 102 | 103 | for i in range(browser_count): 104 | while True: 105 | phone = input(f"请输入第 {i+1} 个手机号: ") 106 | 107 | # 简单验证手机号格式(11位数字) 108 | if phone.isdigit() and len(phone) == 11: 109 | phone_numbers.append(phone) 110 | break 111 | else: 112 | print("手机号格式不正确,请输入11位数字手机号!") 113 | 114 | # 确认输入的手机号 115 | print("\n您输入的手机号如下:") 116 | for i, phone in enumerate(phone_numbers): 117 | print(f"{i+1}. {phone}") 118 | 119 | confirm = input("\n确认使用这些手机号?(y/n): ") 120 | if confirm.lower() != 'y': 121 | print("已取消操作,请重新运行脚本!") 122 | return [] 123 | 124 | return phone_numbers 125 | 126 | if __name__ == "__main__": 127 | # 获取用户输入的浏览器数量 128 | while True: 129 | try: 130 | browser_count = int(input("请输入需要开启的浏览器数量(1-10): ")) 131 | if 1 <= browser_count <= 10: 132 | break 133 | else: 134 | print("请输入1到10之间的数字!") 135 | except ValueError: 136 | print("请输入有效的数字!") 137 | 138 | # 获取用户输入的手机号 139 | phone_numbers = get_user_input_phones(browser_count) 140 | 141 | if phone_numbers: 142 | # 同时打开多个浏览器 143 | open_multiple_browsers(phone_numbers) 144 | else: 145 | print("未输入有效的手机号,脚本已退出。") -------------------------------------------------------------------------------- /.history/auto_phone_fill_20250309063347.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | from selenium.webdriver.support.ui import WebDriverWait 4 | from selenium.webdriver.support import expected_conditions as EC 5 | from selenium.webdriver.chrome.service import Service 6 | from webdriver_manager.chrome import ChromeDriverManager 7 | import time 8 | import threading 9 | 10 | def auto_fill_phone(phone_number): 11 | """ 12 | 自动打开SiliconFlow登录页面并填写手机号 13 | 14 | 参数: 15 | phone_number (str): 要填写的手机号码 16 | """ 17 | print(f"开始为手机号 {phone_number} 自动填写表单...") 18 | 19 | # 初始化Chrome浏览器 20 | options = webdriver.ChromeOptions() 21 | # options.add_argument('--headless') # 无头模式,取消注释可不显示浏览器窗口 22 | 23 | # 初始化WebDriver 24 | driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options) 25 | 26 | try: 27 | # 打开登录页面 28 | url = "https://account.siliconflow.cn/zh/login?redirect=https%3A%2F%2Fcloud.siliconflow.cn%2F%3F" 29 | driver.get(url) 30 | print(f"已为手机号 {phone_number} 打开登录页面") 31 | 32 | # 等待页面加载 33 | time.sleep(2) 34 | 35 | # 找到手机号输入框并填写 36 | # 这里需要根据实际网页元素定位手机号输入框 37 | # 可能的选择器包括:id、name、class name、XPath等 38 | # 下面是一些常见的选择方法,可能需要调整 39 | try: 40 | # 尝试通过placeholder找到输入框 41 | phone_input = WebDriverWait(driver, 10).until( 42 | EC.presence_of_element_located((By.XPATH, "//input[@placeholder='请输入手机号' or contains(@placeholder, '手机号')]")) 43 | ) 44 | phone_input.clear() 45 | phone_input.send_keys(phone_number) 46 | print(f"已成功填写手机号: {phone_number}") 47 | 48 | # 等待一段时间以便查看结果 49 | time.sleep(5) 50 | 51 | except Exception as e: 52 | print(f"填写手机号时出错: {e}") 53 | 54 | # 如果上面的方法失败,可以尝试打印页面源代码帮助调试 55 | print("页面源代码:") 56 | print(driver.page_source) 57 | 58 | finally: 59 | # 关闭浏览器 60 | # 注释掉下一行可以保持浏览器打开以便查看结果 61 | # driver.quit() 62 | print(f"手机号 {phone_number} 脚本执行完毕") 63 | 64 | def open_multiple_browsers(phone_numbers): 65 | """ 66 | 同时打开多个浏览器实例并填写不同的手机号 67 | 68 | 参数: 69 | phone_numbers (list): 要填写的手机号列表 70 | """ 71 | threads = [] 72 | 73 | # 为每个手机号创建一个线程 74 | for phone in phone_numbers: 75 | thread = threading.Thread(target=auto_fill_phone, args=(phone,)) 76 | threads.append(thread) 77 | 78 | # 启动所有线程 79 | for thread in threads: 80 | thread.start() 81 | # 等待一小段时间,避免同时启动多个浏览器导致资源竞争 82 | time.sleep(1) 83 | 84 | # 等待所有线程完成 85 | for thread in threads: 86 | thread.join() 87 | 88 | print("所有浏览器实例已启动完毕") 89 | 90 | def get_user_input_phones(browser_count): 91 | """ 92 | 获取用户输入的手机号 93 | 94 | 参数: 95 | browser_count (int): 需要开启的浏览器数量 96 | 97 | 返回: 98 | list: 用户输入的手机号列表 99 | """ 100 | phone_numbers = [] 101 | print(f"\n请输入{browser_count}个手机号,每个手机号输入完成后按回车确认:") 102 | 103 | for i in range(browser_count): 104 | while True: 105 | phone = input(f"请输入第 {i+1} 个手机号: ") 106 | 107 | # 简单验证手机号格式(11位数字) 108 | if phone.isdigit() and len(phone) == 11: 109 | phone_numbers.append(phone) 110 | break 111 | else: 112 | print("手机号格式不正确,请输入11位数字手机号!") 113 | 114 | print("\n您输入的手机号如下:") 115 | for i, phone in enumerate(phone_numbers): 116 | print(f"{i+1}. {phone}") 117 | 118 | # 移除确认步骤,直接返回手机号列表 119 | return phone_numbers 120 | 121 | if __name__ == "__main__": 122 | # 获取用户输入的浏览器数量 123 | while True: 124 | try: 125 | browser_count = int(input("请输入需要开启的浏览器数量(1-10): ")) 126 | if 1 <= browser_count <= 10: 127 | break 128 | else: 129 | print("请输入1到10之间的数字!") 130 | except ValueError: 131 | print("请输入有效的数字!") 132 | 133 | # 获取用户输入的手机号 134 | phone_numbers = get_user_input_phones(browser_count) 135 | 136 | # 直接运行,不再进行确认 137 | print("\n正在启动浏览器并填写手机号...") 138 | open_multiple_browsers(phone_numbers) -------------------------------------------------------------------------------- /.history/auto_phone_fill_20250309063355.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | from selenium.webdriver.support.ui import WebDriverWait 4 | from selenium.webdriver.support import expected_conditions as EC 5 | from selenium.webdriver.chrome.service import Service 6 | from webdriver_manager.chrome import ChromeDriverManager 7 | import time 8 | import threading 9 | 10 | def auto_fill_phone(phone_number): 11 | """ 12 | 自动打开SiliconFlow登录页面并填写手机号 13 | 14 | 参数: 15 | phone_number (str): 要填写的手机号码 16 | """ 17 | print(f"开始为手机号 {phone_number} 自动填写表单...") 18 | 19 | # 初始化Chrome浏览器 20 | options = webdriver.ChromeOptions() 21 | # options.add_argument('--headless') # 无头模式,取消注释可不显示浏览器窗口 22 | 23 | # 初始化WebDriver 24 | driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options) 25 | 26 | try: 27 | # 打开登录页面 28 | url = "https://account.siliconflow.cn/zh/login?redirect=https%3A%2F%2Fcloud.siliconflow.cn%2F%3F" 29 | driver.get(url) 30 | print(f"已为手机号 {phone_number} 打开登录页面") 31 | 32 | # 等待页面加载 33 | time.sleep(2) 34 | 35 | # 找到手机号输入框并填写 36 | # 这里需要根据实际网页元素定位手机号输入框 37 | # 可能的选择器包括:id、name、class name、XPath等 38 | # 下面是一些常见的选择方法,可能需要调整 39 | try: 40 | # 尝试通过placeholder找到输入框 41 | phone_input = WebDriverWait(driver, 10).until( 42 | EC.presence_of_element_located((By.XPATH, "//input[@placeholder='请输入手机号' or contains(@placeholder, '手机号')]")) 43 | ) 44 | phone_input.clear() 45 | phone_input.send_keys(phone_number) 46 | print(f"已成功填写手机号: {phone_number}") 47 | 48 | # 等待一段时间以便查看结果 49 | time.sleep(5) 50 | 51 | except Exception as e: 52 | print(f"填写手机号时出错: {e}") 53 | 54 | # 如果上面的方法失败,可以尝试打印页面源代码帮助调试 55 | print("页面源代码:") 56 | print(driver.page_source) 57 | 58 | finally: 59 | # 关闭浏览器 60 | # 注释掉下一行可以保持浏览器打开以便查看结果 61 | # driver.quit() 62 | print(f"手机号 {phone_number} 脚本执行完毕") 63 | 64 | def open_multiple_browsers(phone_numbers): 65 | """ 66 | 同时打开多个浏览器实例并填写不同的手机号 67 | 68 | 参数: 69 | phone_numbers (list): 要填写的手机号列表 70 | """ 71 | threads = [] 72 | 73 | # 为每个手机号创建一个线程 74 | for phone in phone_numbers: 75 | thread = threading.Thread(target=auto_fill_phone, args=(phone,)) 76 | threads.append(thread) 77 | 78 | # 启动所有线程 79 | for thread in threads: 80 | thread.start() 81 | # 等待一小段时间,避免同时启动多个浏览器导致资源竞争 82 | time.sleep(1) 83 | 84 | # 等待所有线程完成 85 | for thread in threads: 86 | thread.join() 87 | 88 | print("所有浏览器实例已启动完毕") 89 | 90 | def get_user_input_phones(browser_count): 91 | """ 92 | 获取用户输入的手机号 93 | 94 | 参数: 95 | browser_count (int): 需要开启的浏览器数量 96 | 97 | 返回: 98 | list: 用户输入的手机号列表 99 | """ 100 | phone_numbers = [] 101 | print(f"\n请输入{browser_count}个手机号,每个手机号输入完成后按回车确认:") 102 | 103 | for i in range(browser_count): 104 | while True: 105 | phone = input(f"请输入第 {i+1} 个手机号: ") 106 | 107 | # 简单验证手机号格式(11位数字) 108 | if phone.isdigit() and len(phone) == 11: 109 | phone_numbers.append(phone) 110 | break 111 | else: 112 | print("手机号格式不正确,请输入11位数字手机号!") 113 | 114 | print("\n您输入的手机号如下:") 115 | for i, phone in enumerate(phone_numbers): 116 | print(f"{i+1}. {phone}") 117 | 118 | # 移除确认步骤,直接返回手机号列表 119 | return phone_numbers 120 | 121 | if __name__ == "__main__": 122 | # 获取用户输入的浏览器数量 123 | while True: 124 | try: 125 | browser_count = int(input("请输入需要开启的浏览器数量(1-10): ")) 126 | if 1 <= browser_count <= 10: 127 | break 128 | else: 129 | print("请输入1到10之间的数字!") 130 | except ValueError: 131 | print("请输入有效的数字!") 132 | 133 | # 获取用户输入的手机号 134 | phone_numbers = get_user_input_phones(browser_count) 135 | 136 | # 直接运行,不再进行确认 137 | print("\n正在启动浏览器并填写手机号...") 138 | open_multiple_browsers(phone_numbers) -------------------------------------------------------------------------------- /.history/auto_phone_fill_20250309063745.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | from selenium.webdriver.support.ui import WebDriverWait 4 | from selenium.webdriver.support import expected_conditions as EC 5 | from selenium.webdriver.chrome.service import Service 6 | from webdriver_manager.chrome import ChromeDriverManager 7 | import time 8 | import threading 9 | 10 | # 全局变量存储浏览器驱动实例,防止被垃圾回收 11 | browser_drivers = [] 12 | 13 | def auto_fill_phone(phone_number): 14 | """ 15 | 自动打开SiliconFlow登录页面并填写手机号 16 | 17 | 参数: 18 | phone_number (str): 要填写的手机号码 19 | """ 20 | global browser_drivers 21 | 22 | print(f"开始为手机号 {phone_number} 自动填写表单...") 23 | 24 | # 初始化Chrome浏览器 25 | options = webdriver.ChromeOptions() 26 | options.add_experimental_option("detach", True) # 重要:使浏览器在脚本执行完后保持打开 27 | # options.add_argument('--headless') # 无头模式,取消注释可不显示浏览器窗口 28 | 29 | # 初始化WebDriver 30 | driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options) 31 | # 将驱动实例添加到全局列表中,防止被垃圾回收 32 | browser_drivers.append(driver) 33 | 34 | try: 35 | # 打开登录页面 36 | url = "https://account.siliconflow.cn/zh/login?redirect=https%3A%2F%2Fcloud.siliconflow.cn%2F%3F" 37 | driver.get(url) 38 | print(f"已为手机号 {phone_number} 打开登录页面") 39 | 40 | # 等待页面加载 41 | time.sleep(2) 42 | 43 | # 找到手机号输入框并填写 44 | # 这里需要根据实际网页元素定位手机号输入框 45 | # 可能的选择器包括:id、name、class name、XPath等 46 | # 下面是一些常见的选择方法,可能需要调整 47 | try: 48 | # 尝试通过placeholder找到输入框 49 | phone_input = WebDriverWait(driver, 10).until( 50 | EC.presence_of_element_located((By.XPATH, "//input[@placeholder='请输入手机号' or contains(@placeholder, '手机号')]")) 51 | ) 52 | phone_input.clear() 53 | phone_input.send_keys(phone_number) 54 | print(f"已成功填写手机号: {phone_number}") 55 | 56 | # 等待一段时间以便查看结果 57 | time.sleep(5) 58 | 59 | except Exception as e: 60 | print(f"填写手机号时出错: {e}") 61 | 62 | # 如果上面的方法失败,可以尝试打印页面源代码帮助调试 63 | print("页面源代码:") 64 | print(driver.page_source) 65 | 66 | except Exception as e: 67 | print(f"浏览器操作出错: {e}") 68 | 69 | print(f"手机号 {phone_number} 脚本执行完毕") 70 | # 注意:不要在这里调用driver.quit(),保持浏览器打开 71 | 72 | def open_multiple_browsers(phone_numbers): 73 | """ 74 | 同时打开多个浏览器实例并填写不同的手机号 75 | 76 | 参数: 77 | phone_numbers (list): 要填写的手机号列表 78 | """ 79 | threads = [] 80 | 81 | # 为每个手机号创建一个线程 82 | for phone in phone_numbers: 83 | thread = threading.Thread(target=auto_fill_phone, args=(phone,)) 84 | thread.daemon = False # 设置为非守护线程 85 | threads.append(thread) 86 | 87 | # 启动所有线程 88 | for thread in threads: 89 | thread.start() 90 | # 等待一小段时间,避免同时启动多个浏览器导致资源竞争 91 | time.sleep(1) 92 | 93 | # 等待所有线程完成 94 | for thread in threads: 95 | thread.join() 96 | 97 | print("所有浏览器实例已启动并填写完毕") 98 | 99 | def get_user_input_phones(browser_count): 100 | """ 101 | 获取用户输入的手机号 102 | 103 | 参数: 104 | browser_count (int): 需要开启的浏览器数量 105 | 106 | 返回: 107 | list: 用户输入的手机号列表 108 | """ 109 | phone_numbers = [] 110 | print(f"\n请输入{browser_count}个手机号,每个手机号输入完成后按回车确认:") 111 | 112 | for i in range(browser_count): 113 | while True: 114 | phone = input(f"请输入第 {i+1} 个手机号: ") 115 | 116 | # 简单验证手机号格式(11位数字) 117 | if phone.isdigit() and len(phone) == 11: 118 | phone_numbers.append(phone) 119 | break 120 | else: 121 | print("手机号格式不正确,请输入11位数字手机号!") 122 | 123 | print("\n您输入的手机号如下:") 124 | for i, phone in enumerate(phone_numbers): 125 | print(f"{i+1}. {phone}") 126 | 127 | # 移除确认步骤,直接返回手机号列表 128 | return phone_numbers 129 | 130 | if __name__ == "__main__": 131 | # 获取用户输入的浏览器数量 132 | while True: 133 | try: 134 | browser_count = int(input("请输入需要开启的浏览器数量(1-10): ")) 135 | if 1 <= browser_count <= 10: 136 | break 137 | else: 138 | print("请输入1到10之间的数字!") 139 | except ValueError: 140 | print("请输入有效的数字!") 141 | 142 | # 获取用户输入的手机号 143 | phone_numbers = get_user_input_phones(browser_count) 144 | 145 | # 直接运行,不再进行确认 146 | print("\n正在启动浏览器并填写手机号...") 147 | open_multiple_browsers(phone_numbers) 148 | 149 | # 重要:保持脚本运行,防止浏览器关闭 150 | print("\n所有操作已完成。浏览器将保持打开状态。") 151 | print("请按Ctrl+C手动终止此脚本(当您使用完浏览器后)...") 152 | 153 | # 无限循环保持脚本运行 154 | try: 155 | while True: 156 | time.sleep(1000) 157 | except KeyboardInterrupt: 158 | print("\n脚本已终止,感谢使用!") -------------------------------------------------------------------------------- /.history/auto_phone_fill_20250309063815.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | from selenium.webdriver.support.ui import WebDriverWait 4 | from selenium.webdriver.support import expected_conditions as EC 5 | from selenium.webdriver.chrome.service import Service 6 | from webdriver_manager.chrome import ChromeDriverManager 7 | import time 8 | import threading 9 | 10 | # 全局变量存储浏览器驱动实例,防止被垃圾回收 11 | browser_drivers = [] 12 | 13 | def auto_fill_phone(phone_number): 14 | """ 15 | 自动打开SiliconFlow登录页面并填写手机号 16 | 17 | 参数: 18 | phone_number (str): 要填写的手机号码 19 | """ 20 | global browser_drivers 21 | 22 | print(f"开始为手机号 {phone_number} 自动填写表单...") 23 | 24 | # 初始化Chrome浏览器 25 | options = webdriver.ChromeOptions() 26 | options.add_experimental_option("detach", True) # 重要:使浏览器在脚本执行完后保持打开 27 | # options.add_argument('--headless') # 无头模式,取消注释可不显示浏览器窗口 28 | 29 | # 初始化WebDriver 30 | driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options) 31 | # 将驱动实例添加到全局列表中,防止被垃圾回收 32 | browser_drivers.append(driver) 33 | 34 | try: 35 | # 打开登录页面 36 | url = "https://account.siliconflow.cn/zh/login?redirect=https%3A%2F%2Fcloud.siliconflow.cn%2F%3F" 37 | driver.get(url) 38 | print(f"已为手机号 {phone_number} 打开登录页面") 39 | 40 | # 等待页面加载 41 | time.sleep(2) 42 | 43 | # 找到手机号输入框并填写 44 | # 这里需要根据实际网页元素定位手机号输入框 45 | # 可能的选择器包括:id、name、class name、XPath等 46 | # 下面是一些常见的选择方法,可能需要调整 47 | try: 48 | # 尝试通过placeholder找到输入框 49 | phone_input = WebDriverWait(driver, 10).until( 50 | EC.presence_of_element_located((By.XPATH, "//input[@placeholder='请输入手机号' or contains(@placeholder, '手机号')]")) 51 | ) 52 | phone_input.clear() 53 | phone_input.send_keys(phone_number) 54 | print(f"已成功填写手机号: {phone_number}") 55 | 56 | # 等待一段时间以便查看结果 57 | time.sleep(5) 58 | 59 | except Exception as e: 60 | print(f"填写手机号时出错: {e}") 61 | 62 | # 如果上面的方法失败,可以尝试打印页面源代码帮助调试 63 | print("页面源代码:") 64 | print(driver.page_source) 65 | 66 | except Exception as e: 67 | print(f"浏览器操作出错: {e}") 68 | 69 | print(f"手机号 {phone_number} 脚本执行完毕") 70 | # 注意:不要在这里调用driver.quit(),保持浏览器打开 71 | 72 | def open_multiple_browsers(phone_numbers): 73 | """ 74 | 同时打开多个浏览器实例并填写不同的手机号 75 | 76 | 参数: 77 | phone_numbers (list): 要填写的手机号列表 78 | """ 79 | threads = [] 80 | 81 | # 为每个手机号创建一个线程 82 | for phone in phone_numbers: 83 | thread = threading.Thread(target=auto_fill_phone, args=(phone,)) 84 | thread.daemon = False # 设置为非守护线程 85 | threads.append(thread) 86 | 87 | # 启动所有线程 88 | for thread in threads: 89 | thread.start() 90 | # 等待一小段时间,避免同时启动多个浏览器导致资源竞争 91 | time.sleep(1) 92 | 93 | # 等待所有线程完成 94 | for thread in threads: 95 | thread.join() 96 | 97 | print("所有浏览器实例已启动并填写完毕") 98 | 99 | def get_user_input_phones(browser_count): 100 | """ 101 | 获取用户输入的手机号 102 | 103 | 参数: 104 | browser_count (int): 需要开启的浏览器数量 105 | 106 | 返回: 107 | list: 用户输入的手机号列表 108 | """ 109 | phone_numbers = [] 110 | print(f"\n请输入{browser_count}个手机号,每个手机号输入完成后按回车确认:") 111 | 112 | for i in range(browser_count): 113 | while True: 114 | phone = input(f"请输入第 {i+1} 个手机号: ") 115 | 116 | # 简单验证手机号格式(11位数字) 117 | if phone.isdigit() and len(phone) == 11: 118 | phone_numbers.append(phone) 119 | break 120 | else: 121 | print("手机号格式不正确,请输入11位数字手机号!") 122 | 123 | print("\n您输入的手机号如下:") 124 | for i, phone in enumerate(phone_numbers): 125 | print(f"{i+1}. {phone}") 126 | 127 | # 移除确认步骤,直接返回手机号列表 128 | return phone_numbers 129 | 130 | if __name__ == "__main__": 131 | # 获取用户输入的浏览器数量 132 | while True: 133 | try: 134 | browser_count = int(input("请输入需要开启的浏览器数量(1-10): ")) 135 | if 1 <= browser_count <= 10: 136 | break 137 | else: 138 | print("请输入1到10之间的数字!") 139 | except ValueError: 140 | print("请输入有效的数字!") 141 | 142 | # 获取用户输入的手机号 143 | phone_numbers = get_user_input_phones(browser_count) 144 | 145 | # 直接运行,不再进行确认 146 | print("\n正在启动浏览器并填写手机号...") 147 | open_multiple_browsers(phone_numbers) 148 | 149 | # 重要:保持脚本运行,防止浏览器关闭 150 | print("\n所有操作已完成。浏览器将保持打开状态。") 151 | print("请按Ctrl+C手动终止此脚本(当您使用完浏览器后)...") 152 | 153 | # 无限循环保持脚本运行 154 | try: 155 | while True: 156 | time.sleep(1000) 157 | except KeyboardInterrupt: 158 | print("\n脚本已终止,感谢使用!") -------------------------------------------------------------------------------- /.history/auto_phone_fill_20250309064340.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | from selenium.webdriver.support.ui import WebDriverWait 4 | from selenium.webdriver.support import expected_conditions as EC 5 | from selenium.webdriver.chrome.service import Service 6 | from webdriver_manager.chrome import ChromeDriverManager 7 | from selenium.webdriver.common.action_chains import ActionChains 8 | from selenium.webdriver.common.keys import Keys 9 | import time 10 | import threading 11 | import random 12 | import string 13 | 14 | # 全局变量存储浏览器驱动实例,防止被垃圾回收 15 | browser_drivers = [] 16 | 17 | def random_sleep(min_seconds=0.5, max_seconds=2.0): 18 | """随机睡眠一段时间,模拟人类行为""" 19 | time.sleep(random.uniform(min_seconds, max_seconds)) 20 | 21 | def human_like_typing(element, text): 22 | """模拟人类输入,有随机间隔""" 23 | for char in text: 24 | element.send_keys(char) 25 | # 随机短暂停顿,模拟人类打字速度 26 | time.sleep(random.uniform(0.05, 0.25)) 27 | 28 | def auto_fill_phone(phone_number): 29 | """ 30 | 自动打开SiliconFlow登录页面并填写手机号 31 | 32 | 参数: 33 | phone_number (str): 要填写的手机号码 34 | """ 35 | global browser_drivers 36 | 37 | print(f"开始为手机号 {phone_number} 自动填写表单...") 38 | 39 | # 初始化Chrome浏览器 40 | options = webdriver.ChromeOptions() 41 | options.add_experimental_option("detach", True) # 使浏览器在脚本执行完后保持打开 42 | 43 | # 隐藏自动化特征 44 | options.add_experimental_option("excludeSwitches", ["enable-automation"]) 45 | options.add_experimental_option('useAutomationExtension', False) 46 | 47 | # 添加随机用户代理 48 | user_agents = [ 49 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36", 50 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", 51 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0", 52 | "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15", 53 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0" 54 | ] 55 | options.add_argument(f"user-agent={random.choice(user_agents)}") 56 | 57 | # 初始化WebDriver 58 | driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options) 59 | 60 | # 设置窗口大小为常见的尺寸 61 | common_resolutions = [ 62 | (1920, 1080), (1366, 768), (1536, 864), (1440, 900), 63 | (1280, 720), (1600, 900), (1280, 800), (1280, 1024) 64 | ] 65 | window_size = random.choice(common_resolutions) 66 | driver.set_window_size(window_size[0], window_size[1]) 67 | 68 | # 添加反检测脚本 69 | driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", { 70 | "source": """ 71 | Object.defineProperty(navigator, 'webdriver', { 72 | get: () => undefined 73 | }); 74 | // 修改navigator属性以隐藏自动化特征 75 | const originalQuery = window.navigator.permissions.query; 76 | window.navigator.permissions.query = (parameters) => ( 77 | parameters.name === 'notifications' ? 78 | Promise.resolve({ state: Notification.permission }) : 79 | originalQuery(parameters) 80 | ); 81 | """ 82 | }) 83 | 84 | # 将驱动实例添加到全局列表中,防止被垃圾回收 85 | browser_drivers.append(driver) 86 | 87 | try: 88 | # 打开登录页面 89 | url = "https://account.siliconflow.cn/zh/login?redirect=https%3A%2F%2Fcloud.siliconflow.cn%2F%3F" 90 | driver.get(url) 91 | print(f"已为手机号 {phone_number} 打开登录页面") 92 | 93 | # 添加随机延迟,模拟人类阅读页面 94 | random_sleep(1.5, 3.0) 95 | 96 | # 模拟鼠标随机移动 97 | action = ActionChains(driver) 98 | for _ in range(random.randint(3, 6)): 99 | x, y = random.randint(100, 700), random.randint(100, 500) 100 | action.move_by_offset(x, y).perform() 101 | random_sleep(0.3, 0.8) 102 | # 重置鼠标位置 103 | action.move_by_offset(-x, -y).perform() 104 | 105 | # 找到手机号输入框并填写 106 | try: 107 | # 尝试通过placeholder找到输入框 108 | phone_input = WebDriverWait(driver, 10).until( 109 | EC.presence_of_element_located((By.XPATH, "//input[@placeholder='请输入手机号' or contains(@placeholder, '手机号')]")) 110 | ) 111 | 112 | # 首先点击输入框 113 | action.move_to_element(phone_input).click().perform() 114 | random_sleep(0.3, 0.8) 115 | 116 | # 清空输入框 117 | phone_input.clear() 118 | random_sleep(0.2, 0.5) 119 | 120 | # 使用人类般的输入方式 121 | human_like_typing(phone_input, phone_number) 122 | 123 | print(f"已成功填写手机号: {phone_number}") 124 | 125 | # 随机延迟,模拟人类行为 126 | random_sleep(1.0, 2.0) 127 | 128 | # 可选:按下Tab键,模拟人类操作 129 | action.send_keys(Keys.TAB).perform() 130 | random_sleep(0.5, 1.0) 131 | 132 | except Exception as e: 133 | print(f"填写手机号时出错: {e}") 134 | 135 | # 如果上面的方法失败,可以尝试打印页面源代码帮助调试 136 | print("页面源代码:") 137 | print(driver.page_source) 138 | 139 | except Exception as e: 140 | print(f"浏览器操作出错: {e}") 141 | 142 | print(f"手机号 {phone_number} 脚本执行完毕") 143 | # 注意:不要在这里调用driver.quit(),保持浏览器打开 144 | 145 | def open_multiple_browsers(phone_numbers): 146 | """ 147 | 同时打开多个浏览器实例并填写不同的手机号 148 | 149 | 参数: 150 | phone_numbers (list): 要填写的手机号列表 151 | """ 152 | threads = [] 153 | 154 | # 为每个手机号创建一个线程 155 | for phone in phone_numbers: 156 | thread = threading.Thread(target=auto_fill_phone, args=(phone,)) 157 | thread.daemon = False # 设置为非守护线程 158 | threads.append(thread) 159 | 160 | # 启动所有线程 161 | for thread in threads: 162 | thread.start() 163 | # 每个浏览器启动间隔随机延迟,更像人类行为 164 | random_sleep(1.5, 3.0) 165 | 166 | # 等待所有线程完成 167 | for thread in threads: 168 | thread.join() 169 | 170 | print("所有浏览器实例已启动并填写完毕") 171 | 172 | def get_user_input_phones(browser_count): 173 | """ 174 | 获取用户输入的手机号 175 | 176 | 参数: 177 | browser_count (int): 需要开启的浏览器数量 178 | 179 | 返回: 180 | list: 用户输入的手机号列表 181 | """ 182 | phone_numbers = [] 183 | print(f"\n请输入{browser_count}个手机号,每个手机号输入完成后按回车确认:") 184 | 185 | for i in range(browser_count): 186 | while True: 187 | phone = input(f"请输入第 {i+1} 个手机号: ") 188 | 189 | # 简单验证手机号格式(11位数字) 190 | if phone.isdigit() and len(phone) == 11: 191 | phone_numbers.append(phone) 192 | break 193 | else: 194 | print("手机号格式不正确,请输入11位数字手机号!") 195 | 196 | print("\n您输入的手机号如下:") 197 | for i, phone in enumerate(phone_numbers): 198 | print(f"{i+1}. {phone}") 199 | 200 | # 移除确认步骤,直接返回手机号列表 201 | return phone_numbers 202 | 203 | if __name__ == "__main__": 204 | # 获取用户输入的浏览器数量 205 | while True: 206 | try: 207 | browser_count = int(input("请输入需要开启的浏览器数量(1-10): ")) 208 | if 1 <= browser_count <= 10: 209 | break 210 | else: 211 | print("请输入1到10之间的数字!") 212 | except ValueError: 213 | print("请输入有效的数字!") 214 | 215 | # 获取用户输入的手机号 216 | phone_numbers = get_user_input_phones(browser_count) 217 | 218 | # 直接运行,不再进行确认 219 | print("\n正在启动浏览器并填写手机号...") 220 | open_multiple_browsers(phone_numbers) 221 | 222 | # 重要:保持脚本运行,防止浏览器关闭 223 | print("\n所有操作已完成。浏览器将保持打开状态。") 224 | print("请按Ctrl+C手动终止此脚本(当您使用完浏览器后)...") 225 | 226 | # 无限循环保持脚本运行 227 | try: 228 | while True: 229 | time.sleep(1000) 230 | except KeyboardInterrupt: 231 | print("\n脚本已终止,感谢使用!") -------------------------------------------------------------------------------- /.history/auto_phone_fill_20250309065817.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | from selenium.webdriver.support.ui import WebDriverWait 4 | from selenium.webdriver.support import expected_conditions as EC 5 | from selenium.webdriver.chrome.service import Service 6 | from webdriver_manager.chrome import ChromeDriverManager 7 | from selenium.webdriver.common.action_chains import ActionChains 8 | from selenium.webdriver.common.keys import Keys 9 | import time 10 | import threading 11 | import random 12 | import string 13 | 14 | # 全局变量存储浏览器驱动实例,防止被垃圾回收 15 | browser_drivers = [] 16 | 17 | def random_sleep(min_seconds=0.5, max_seconds=2.0): 18 | """随机睡眠一段时间,模拟人类行为""" 19 | time.sleep(random.uniform(min_seconds, max_seconds)) 20 | 21 | def human_like_typing(element, text): 22 | """模拟人类输入,有随机间隔""" 23 | for char in text: 24 | element.send_keys(char) 25 | # 随机短暂停顿,模拟人类打字速度 26 | time.sleep(random.uniform(0.05, 0.25)) 27 | 28 | def auto_fill_phone(phone_number): 29 | """ 30 | 自动打开SiliconFlow登录页面并填写手机号 31 | 32 | 参数: 33 | phone_number (str): 要填写的手机号码 34 | """ 35 | global browser_drivers 36 | 37 | print(f"开始为手机号 {phone_number} 自动填写表单...") 38 | 39 | # 初始化Chrome浏览器 40 | options = webdriver.ChromeOptions() 41 | options.add_experimental_option("detach", True) # 使浏览器在脚本执行完后保持打开 42 | 43 | # 隐藏自动化特征 44 | options.add_experimental_option("excludeSwitches", ["enable-automation"]) 45 | options.add_experimental_option('useAutomationExtension', False) 46 | 47 | # 添加随机用户代理 48 | user_agents = [ 49 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36", 50 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", 51 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0", 52 | "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15", 53 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0" 54 | ] 55 | options.add_argument(f"user-agent={random.choice(user_agents)}") 56 | 57 | # 初始化WebDriver 58 | driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options) 59 | 60 | # 设置窗口大小为常见的尺寸 61 | common_resolutions = [ 62 | (1920, 1080), (1366, 768), (1536, 864), (1440, 900), 63 | (1280, 720), (1600, 900), (1280, 800), (1280, 1024) 64 | ] 65 | window_size = random.choice(common_resolutions) 66 | driver.set_window_size(window_size[0], window_size[1]) 67 | 68 | # 添加反检测脚本 69 | driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", { 70 | "source": """ 71 | Object.defineProperty(navigator, 'webdriver', { 72 | get: () => undefined 73 | }); 74 | // 修改navigator属性以隐藏自动化特征 75 | const originalQuery = window.navigator.permissions.query; 76 | window.navigator.permissions.query = (parameters) => ( 77 | parameters.name === 'notifications' ? 78 | Promise.resolve({ state: Notification.permission }) : 79 | originalQuery(parameters) 80 | ); 81 | """ 82 | }) 83 | 84 | # 将驱动实例添加到全局列表中,防止被垃圾回收 85 | browser_drivers.append(driver) 86 | 87 | try: 88 | # 打开登录页面 89 | url = "https://account.siliconflow.cn/zh/login?redirect=https%3A%2F%2Fcloud.siliconflow.cn%2F%3F" 90 | driver.get(url) 91 | print(f"已为手机号 {phone_number} 打开登录页面") 92 | 93 | # 添加随机延迟,模拟人类阅读页面 94 | random_sleep(1.5, 3.0) 95 | 96 | # 模拟鼠标随机移动 97 | action = ActionChains(driver) 98 | for _ in range(random.randint(3, 6)): 99 | x, y = random.randint(100, 700), random.randint(100, 500) 100 | action.move_by_offset(x, y).perform() 101 | random_sleep(0.3, 0.8) 102 | # 重置鼠标位置 103 | action.move_by_offset(-x, -y).perform() 104 | 105 | # 找到手机号输入框并填写 106 | try: 107 | # 尝试通过placeholder找到输入框 108 | phone_input = WebDriverWait(driver, 10).until( 109 | EC.presence_of_element_located((By.XPATH, "//input[@placeholder='请输入手机号' or contains(@placeholder, '手机号')]")) 110 | ) 111 | 112 | # 首先点击输入框 113 | action.move_to_element(phone_input).click().perform() 114 | random_sleep(0.3, 0.8) 115 | 116 | # 清空输入框 117 | phone_input.clear() 118 | random_sleep(0.2, 0.5) 119 | 120 | # 使用人类般的输入方式 121 | human_like_typing(phone_input, phone_number) 122 | 123 | print(f"已成功填写手机号: {phone_number}") 124 | 125 | # 随机延迟,模拟人类行为 126 | random_sleep(1.0, 2.0) 127 | 128 | # 可选:按下Tab键,模拟人类操作 129 | action.send_keys(Keys.TAB).perform() 130 | random_sleep(0.5, 1.0) 131 | 132 | except Exception as e: 133 | print(f"填写手机号时出错: {e}") 134 | 135 | # 如果上面的方法失败,可以尝试打印页面源代码帮助调试 136 | print("页面源代码:") 137 | print(driver.page_source) 138 | 139 | except Exception as e: 140 | print(f"浏览器操作出错: {e}") 141 | 142 | print(f"手机号 {phone_number} 脚本执行完毕") 143 | # 注意:不要在这里调用driver.quit(),保持浏览器打开 144 | 145 | def open_multiple_browsers(phone_numbers): 146 | """ 147 | 同时打开多个浏览器实例并填写不同的手机号 148 | 149 | 参数: 150 | phone_numbers (list): 要填写的手机号列表 151 | """ 152 | threads = [] 153 | 154 | # 为每个手机号创建一个线程 155 | for phone in phone_numbers: 156 | thread = threading.Thread(target=auto_fill_phone, args=(phone,)) 157 | thread.daemon = False # 设置为非守护线程 158 | threads.append(thread) 159 | 160 | # 启动所有线程 161 | for thread in threads: 162 | thread.start() 163 | # 每个浏览器启动间隔随机延迟,更像人类行为 164 | random_sleep(1.5, 3.0) 165 | 166 | # 等待所有线程完成 167 | for thread in threads: 168 | thread.join() 169 | 170 | print("所有浏览器实例已启动并填写完毕") 171 | 172 | def get_user_input_phones(browser_count): 173 | """ 174 | 获取用户输入的手机号 175 | 176 | 参数: 177 | browser_count (int): 需要开启的浏览器数量 178 | 179 | 返回: 180 | list: 用户输入的手机号列表 181 | """ 182 | phone_numbers = [] 183 | print(f"\n请输入{browser_count}个手机号,每个手机号输入完成后按回车确认:") 184 | 185 | for i in range(browser_count): 186 | while True: 187 | phone = input(f"请输入第 {i+1} 个手机号: ") 188 | 189 | # 简单验证手机号格式(11位数字) 190 | if phone.isdigit() and len(phone) == 11: 191 | phone_numbers.append(phone) 192 | break 193 | else: 194 | print("手机号格式不正确,请输入11位数字手机号!") 195 | 196 | print("\n您输入的手机号如下:") 197 | for i, phone in enumerate(phone_numbers): 198 | print(f"{i+1}. {phone}") 199 | 200 | # 移除确认步骤,直接返回手机号列表 201 | return phone_numbers 202 | 203 | if __name__ == "__main__": 204 | # 获取用户输入的浏览器数量 205 | while True: 206 | try: 207 | browser_count = int(input("请输入需要开启的浏览器数量(1-10): ")) 208 | if 1 <= browser_count <= 10: 209 | break 210 | else: 211 | print("请输入1到10之间的数字!") 212 | except ValueError: 213 | print("请输入有效的数字!") 214 | 215 | # 获取用户输入的手机号 216 | phone_numbers = get_user_input_phones(browser_count) 217 | 218 | # 直接运行,不再进行确认 219 | print("\n正在启动浏览器并填写手机号...") 220 | open_multiple_browsers(phone_numbers) 221 | 222 | # 重要:保持脚本运行,防止浏览器关闭 223 | print("\n所有操作已完成。浏览器将保持打开状态。") 224 | print("请按Ctrl+C手动终止此脚本(当您使用完浏览器后)...") 225 | 226 | # 无限循环保持脚本运行 227 | try: 228 | while True: 229 | time.sleep(1000) 230 | except KeyboardInterrupt: 231 | print("\n脚本已终止,感谢使用!") -------------------------------------------------------------------------------- /.history/auto_phone_fill_20250309070144.py: -------------------------------------------------------------------------------- 1 | import undetected_chromedriver as uc 2 | from selenium.webdriver.common.by import By 3 | from selenium.webdriver.support.ui import WebDriverWait 4 | from selenium.webdriver.support import expected_conditions as EC 5 | from selenium.webdriver.common.action_chains import ActionChains 6 | from selenium.webdriver.common.keys import Keys 7 | import time 8 | import threading 9 | import random 10 | import string 11 | import os 12 | 13 | # 全局变量存储浏览器驱动实例,防止被垃圾回收 14 | browser_drivers = [] 15 | 16 | def random_sleep(min_seconds=0.5, max_seconds=2.0): 17 | """随机睡眠一段时间,模拟人类行为""" 18 | time.sleep(random.uniform(min_seconds, max_seconds)) 19 | 20 | def human_like_typing(element, text): 21 | """模拟人类输入,有随机间隔""" 22 | for char in text: 23 | element.send_keys(char) 24 | # 随机短暂停顿,模拟人类打字速度 25 | time.sleep(random.uniform(0.05, 0.25)) 26 | 27 | def auto_fill_phone(phone_number): 28 | """ 29 | 自动打开SiliconFlow登录页面并填写手机号 30 | 31 | 参数: 32 | phone_number (str): 要填写的手机号码 33 | """ 34 | global browser_drivers 35 | 36 | print(f"开始为手机号 {phone_number} 自动填写表单...") 37 | 38 | # 创建一个临时目录作为用户数据目录,每次使用不同的目录以隔离会话 39 | user_data_dir = f"chrome_user_data_{phone_number}" 40 | 41 | # 确保目录存在 42 | os.makedirs(user_data_dir, exist_ok=True) 43 | 44 | try: 45 | # 使用undetected_chromedriver而不是标准selenium 46 | options = uc.ChromeOptions() 47 | 48 | # 添加随机用户代理 49 | user_agents = [ 50 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36", 51 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", 52 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0", 53 | "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15", 54 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0" 55 | ] 56 | options.add_argument(f"user-agent={random.choice(user_agents)}") 57 | 58 | # 设置用户数据目录 59 | options.add_argument(f"--user-data-dir={os.path.abspath(user_data_dir)}") 60 | 61 | # 设置首次运行参数,避免显示首次运行对话框 62 | options.add_argument("--no-first-run") 63 | options.add_argument("--no-default-browser-check") 64 | 65 | # 增加随机性,避免指纹追踪 66 | options.add_argument(f"--window-size={random.randint(1000, 1920)},{random.randint(700, 1080)}") 67 | 68 | # 增加会话隐私性 69 | options.add_argument("--incognito") 70 | 71 | # 禁用自动化扩展 72 | options.add_argument("--disable-blink-features=AutomationControlled") 73 | 74 | # 初始化undetected_chromedriver 75 | driver = uc.Chrome(options=options, driver_executable_path=None, headless=False) 76 | 77 | # 将驱动实例添加到全局列表中,防止被垃圾回收 78 | browser_drivers.append(driver) 79 | 80 | # 设置隐式等待 81 | driver.implicitly_wait(10) 82 | 83 | # 打开登录页面 84 | url = "https://account.siliconflow.cn/zh/login?redirect=https%3A%2F%2Fcloud.siliconflow.cn%2F%3F" 85 | driver.get(url) 86 | print(f"已为手机号 {phone_number} 打开登录页面") 87 | 88 | # 随机延迟,模拟人类阅读页面 89 | random_sleep(1.0, 3.0) 90 | 91 | # 模拟人类行为 - 滚动页面 92 | driver.execute_script(f"window.scrollBy(0, {random.randint(100, 300)});") 93 | random_sleep(0.5, 1.5) 94 | driver.execute_script(f"window.scrollBy(0, {random.randint(-100, -50)});") 95 | random_sleep(0.3, 0.8) 96 | 97 | # 尝试找到并填写手机号输入框 98 | try: 99 | # 尝试通过各种选择器找到输入框 100 | selectors = [ 101 | "//input[@placeholder='请输入手机号' or contains(@placeholder, '手机号')]", 102 | "//input[contains(@class, 'phone') or contains(@name, 'phone') or contains(@id, 'phone')]", 103 | "//input[@type='tel']" 104 | ] 105 | 106 | phone_input = None 107 | for selector in selectors: 108 | try: 109 | elements = driver.find_elements(By.XPATH, selector) 110 | if elements: 111 | phone_input = elements[0] 112 | break 113 | except: 114 | continue 115 | 116 | if not phone_input: 117 | print("未找到手机号输入框,尝试查看页面源码...") 118 | print(driver.page_source) 119 | return 120 | 121 | # 鼠标移动到输入框 122 | action = ActionChains(driver) 123 | action.move_to_element(phone_input).perform() 124 | random_sleep(0.3, 0.7) 125 | 126 | # 点击输入框 127 | action.click().perform() 128 | random_sleep(0.2, 0.6) 129 | 130 | # 清空输入框 131 | phone_input.clear() 132 | random_sleep(0.2, 0.4) 133 | 134 | # 模拟人类输入 135 | human_like_typing(phone_input, phone_number) 136 | 137 | print(f"已成功填写手机号: {phone_number}") 138 | 139 | # 随机延迟,模拟人类行为 140 | random_sleep(0.8, 1.5) 141 | 142 | # 可能的后续操作,如按下Tab键或点击获取验证码 143 | if random.choice([True, False]): 144 | action.send_keys(Keys.TAB).perform() 145 | else: 146 | # 尝试查找并点击验证码按钮,但不强制 147 | try: 148 | code_buttons = driver.find_elements(By.XPATH, "//button[contains(text(), '验证码') or contains(text(), '获取')]") 149 | if code_buttons: 150 | # 鼠标移动到按钮 151 | action.move_to_element(code_buttons[0]).perform() 152 | random_sleep(0.3, 0.8) 153 | # 不实际点击,让用户自己点击 154 | except: 155 | pass 156 | 157 | except Exception as e: 158 | print(f"填写手机号时出错: {e}") 159 | 160 | # 如果上面的方法失败,可以尝试打印页面源代码帮助调试 161 | print("页面源代码:") 162 | print(driver.page_source) 163 | 164 | except Exception as e: 165 | print(f"浏览器操作出错: {e}") 166 | 167 | print(f"手机号 {phone_number} 脚本执行完毕") 168 | # 注意:不要在这里调用driver.quit(),保持浏览器打开 169 | 170 | def open_multiple_browsers(phone_numbers): 171 | """ 172 | 同时打开多个浏览器实例并填写不同的手机号 173 | 174 | 参数: 175 | phone_numbers (list): 要填写的手机号列表 176 | """ 177 | threads = [] 178 | 179 | # 为每个手机号创建一个线程 180 | for phone in phone_numbers: 181 | thread = threading.Thread(target=auto_fill_phone, args=(phone,)) 182 | thread.daemon = False # 设置为非守护线程 183 | threads.append(thread) 184 | 185 | # 启动所有线程 186 | for thread in threads: 187 | thread.start() 188 | # 每个浏览器启动间隔随机延迟,更像人类行为 189 | random_sleep(2.0, 5.0) 190 | 191 | # 等待所有线程完成 192 | for thread in threads: 193 | thread.join() 194 | 195 | print("所有浏览器实例已启动并填写完毕") 196 | 197 | def get_user_input_phones(browser_count): 198 | """ 199 | 获取用户输入的手机号 200 | 201 | 参数: 202 | browser_count (int): 需要开启的浏览器数量 203 | 204 | 返回: 205 | list: 用户输入的手机号列表 206 | """ 207 | phone_numbers = [] 208 | print(f"\n请输入{browser_count}个手机号,每个手机号输入完成后按回车确认:") 209 | 210 | for i in range(browser_count): 211 | while True: 212 | phone = input(f"请输入第 {i+1} 个手机号: ") 213 | 214 | # 简单验证手机号格式(11位数字) 215 | if phone.isdigit() and len(phone) == 11: 216 | phone_numbers.append(phone) 217 | break 218 | else: 219 | print("手机号格式不正确,请输入11位数字手机号!") 220 | 221 | print("\n您输入的手机号如下:") 222 | for i, phone in enumerate(phone_numbers): 223 | print(f"{i+1}. {phone}") 224 | 225 | # 移除确认步骤,直接返回手机号列表 226 | return phone_numbers 227 | 228 | if __name__ == "__main__": 229 | # 获取用户输入的浏览器数量 230 | while True: 231 | try: 232 | browser_count = int(input("请输入需要开启的浏览器数量(1-10): ")) 233 | if 1 <= browser_count <= 10: 234 | break 235 | else: 236 | print("请输入1到10之间的数字!") 237 | except ValueError: 238 | print("请输入有效的数字!") 239 | 240 | # 获取用户输入的手机号 241 | phone_numbers = get_user_input_phones(browser_count) 242 | 243 | # 直接运行,不再进行确认 244 | print("\n正在启动浏览器并填写手机号...") 245 | open_multiple_browsers(phone_numbers) 246 | 247 | # 重要:保持脚本运行,防止浏览器关闭 248 | print("\n所有操作已完成。浏览器将保持打开状态。") 249 | print("请按Ctrl+C手动终止此脚本(当您使用完浏览器后)...") 250 | 251 | # 无限循环保持脚本运行 252 | try: 253 | while True: 254 | time.sleep(1000) 255 | except KeyboardInterrupt: 256 | print("\n脚本已终止,感谢使用!") -------------------------------------------------------------------------------- /.history/auto_phone_fill_20250309070215.py: -------------------------------------------------------------------------------- 1 | import undetected_chromedriver as uc 2 | from selenium.webdriver.common.by import By 3 | from selenium.webdriver.support.ui import WebDriverWait 4 | from selenium.webdriver.support import expected_conditions as EC 5 | from selenium.webdriver.common.action_chains import ActionChains 6 | from selenium.webdriver.common.keys import Keys 7 | import time 8 | import threading 9 | import random 10 | import string 11 | import os 12 | 13 | # 全局变量存储浏览器驱动实例,防止被垃圾回收 14 | browser_drivers = [] 15 | 16 | def random_sleep(min_seconds=0.5, max_seconds=2.0): 17 | """随机睡眠一段时间,模拟人类行为""" 18 | time.sleep(random.uniform(min_seconds, max_seconds)) 19 | 20 | def human_like_typing(element, text): 21 | """模拟人类输入,有随机间隔""" 22 | for char in text: 23 | element.send_keys(char) 24 | # 随机短暂停顿,模拟人类打字速度 25 | time.sleep(random.uniform(0.05, 0.25)) 26 | 27 | def auto_fill_phone(phone_number): 28 | """ 29 | 自动打开SiliconFlow登录页面并填写手机号 30 | 31 | 参数: 32 | phone_number (str): 要填写的手机号码 33 | """ 34 | global browser_drivers 35 | 36 | print(f"开始为手机号 {phone_number} 自动填写表单...") 37 | 38 | # 创建一个临时目录作为用户数据目录,每次使用不同的目录以隔离会话 39 | user_data_dir = f"chrome_user_data_{phone_number}" 40 | 41 | # 确保目录存在 42 | os.makedirs(user_data_dir, exist_ok=True) 43 | 44 | try: 45 | # 使用undetected_chromedriver而不是标准selenium 46 | options = uc.ChromeOptions() 47 | 48 | # 添加随机用户代理 49 | user_agents = [ 50 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36", 51 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", 52 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0", 53 | "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15", 54 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0" 55 | ] 56 | options.add_argument(f"user-agent={random.choice(user_agents)}") 57 | 58 | # 设置用户数据目录 59 | options.add_argument(f"--user-data-dir={os.path.abspath(user_data_dir)}") 60 | 61 | # 设置首次运行参数,避免显示首次运行对话框 62 | options.add_argument("--no-first-run") 63 | options.add_argument("--no-default-browser-check") 64 | 65 | # 增加随机性,避免指纹追踪 66 | options.add_argument(f"--window-size={random.randint(1000, 1920)},{random.randint(700, 1080)}") 67 | 68 | # 增加会话隐私性 69 | options.add_argument("--incognito") 70 | 71 | # 禁用自动化扩展 72 | options.add_argument("--disable-blink-features=AutomationControlled") 73 | 74 | # 初始化undetected_chromedriver 75 | driver = uc.Chrome(options=options, driver_executable_path=None, headless=False) 76 | 77 | # 将驱动实例添加到全局列表中,防止被垃圾回收 78 | browser_drivers.append(driver) 79 | 80 | # 设置隐式等待 81 | driver.implicitly_wait(10) 82 | 83 | # 打开登录页面 84 | url = "https://account.siliconflow.cn/zh/login?redirect=https%3A%2F%2Fcloud.siliconflow.cn%2F%3F" 85 | driver.get(url) 86 | print(f"已为手机号 {phone_number} 打开登录页面") 87 | 88 | # 随机延迟,模拟人类阅读页面 89 | random_sleep(1.0, 3.0) 90 | 91 | # 模拟人类行为 - 滚动页面 92 | driver.execute_script(f"window.scrollBy(0, {random.randint(100, 300)});") 93 | random_sleep(0.5, 1.5) 94 | driver.execute_script(f"window.scrollBy(0, {random.randint(-100, -50)});") 95 | random_sleep(0.3, 0.8) 96 | 97 | # 尝试找到并填写手机号输入框 98 | try: 99 | # 尝试通过各种选择器找到输入框 100 | selectors = [ 101 | "//input[@placeholder='请输入手机号' or contains(@placeholder, '手机号')]", 102 | "//input[contains(@class, 'phone') or contains(@name, 'phone') or contains(@id, 'phone')]", 103 | "//input[@type='tel']" 104 | ] 105 | 106 | phone_input = None 107 | for selector in selectors: 108 | try: 109 | elements = driver.find_elements(By.XPATH, selector) 110 | if elements: 111 | phone_input = elements[0] 112 | break 113 | except: 114 | continue 115 | 116 | if not phone_input: 117 | print("未找到手机号输入框,尝试查看页面源码...") 118 | print(driver.page_source) 119 | return 120 | 121 | # 鼠标移动到输入框 122 | action = ActionChains(driver) 123 | action.move_to_element(phone_input).perform() 124 | random_sleep(0.3, 0.7) 125 | 126 | # 点击输入框 127 | action.click().perform() 128 | random_sleep(0.2, 0.6) 129 | 130 | # 清空输入框 131 | phone_input.clear() 132 | random_sleep(0.2, 0.4) 133 | 134 | # 模拟人类输入 135 | human_like_typing(phone_input, phone_number) 136 | 137 | print(f"已成功填写手机号: {phone_number}") 138 | 139 | # 随机延迟,模拟人类行为 140 | random_sleep(0.8, 1.5) 141 | 142 | # 可能的后续操作,如按下Tab键或点击获取验证码 143 | if random.choice([True, False]): 144 | action.send_keys(Keys.TAB).perform() 145 | else: 146 | # 尝试查找并点击验证码按钮,但不强制 147 | try: 148 | code_buttons = driver.find_elements(By.XPATH, "//button[contains(text(), '验证码') or contains(text(), '获取')]") 149 | if code_buttons: 150 | # 鼠标移动到按钮 151 | action.move_to_element(code_buttons[0]).perform() 152 | random_sleep(0.3, 0.8) 153 | # 不实际点击,让用户自己点击 154 | except: 155 | pass 156 | 157 | except Exception as e: 158 | print(f"填写手机号时出错: {e}") 159 | 160 | # 如果上面的方法失败,可以尝试打印页面源代码帮助调试 161 | print("页面源代码:") 162 | print(driver.page_source) 163 | 164 | except Exception as e: 165 | print(f"浏览器操作出错: {e}") 166 | 167 | print(f"手机号 {phone_number} 脚本执行完毕") 168 | # 注意:不要在这里调用driver.quit(),保持浏览器打开 169 | 170 | def open_multiple_browsers(phone_numbers): 171 | """ 172 | 同时打开多个浏览器实例并填写不同的手机号 173 | 174 | 参数: 175 | phone_numbers (list): 要填写的手机号列表 176 | """ 177 | threads = [] 178 | 179 | # 为每个手机号创建一个线程 180 | for phone in phone_numbers: 181 | thread = threading.Thread(target=auto_fill_phone, args=(phone,)) 182 | thread.daemon = False # 设置为非守护线程 183 | threads.append(thread) 184 | 185 | # 启动所有线程 186 | for thread in threads: 187 | thread.start() 188 | # 每个浏览器启动间隔随机延迟,更像人类行为 189 | random_sleep(2.0, 5.0) 190 | 191 | # 等待所有线程完成 192 | for thread in threads: 193 | thread.join() 194 | 195 | print("所有浏览器实例已启动并填写完毕") 196 | 197 | def get_user_input_phones(browser_count): 198 | """ 199 | 获取用户输入的手机号 200 | 201 | 参数: 202 | browser_count (int): 需要开启的浏览器数量 203 | 204 | 返回: 205 | list: 用户输入的手机号列表 206 | """ 207 | phone_numbers = [] 208 | print(f"\n请输入{browser_count}个手机号,每个手机号输入完成后按回车确认:") 209 | 210 | for i in range(browser_count): 211 | while True: 212 | phone = input(f"请输入第 {i+1} 个手机号: ") 213 | 214 | # 简单验证手机号格式(11位数字) 215 | if phone.isdigit() and len(phone) == 11: 216 | phone_numbers.append(phone) 217 | break 218 | else: 219 | print("手机号格式不正确,请输入11位数字手机号!") 220 | 221 | print("\n您输入的手机号如下:") 222 | for i, phone in enumerate(phone_numbers): 223 | print(f"{i+1}. {phone}") 224 | 225 | # 移除确认步骤,直接返回手机号列表 226 | return phone_numbers 227 | 228 | if __name__ == "__main__": 229 | # 获取用户输入的浏览器数量 230 | while True: 231 | try: 232 | browser_count = int(input("请输入需要开启的浏览器数量(1-10): ")) 233 | if 1 <= browser_count <= 10: 234 | break 235 | else: 236 | print("请输入1到10之间的数字!") 237 | except ValueError: 238 | print("请输入有效的数字!") 239 | 240 | # 获取用户输入的手机号 241 | phone_numbers = get_user_input_phones(browser_count) 242 | 243 | # 直接运行,不再进行确认 244 | print("\n正在启动浏览器并填写手机号...") 245 | open_multiple_browsers(phone_numbers) 246 | 247 | # 重要:保持脚本运行,防止浏览器关闭 248 | print("\n所有操作已完成。浏览器将保持打开状态。") 249 | print("请按Ctrl+C手动终止此脚本(当您使用完浏览器后)...") 250 | 251 | # 无限循环保持脚本运行 252 | try: 253 | while True: 254 | time.sleep(1000) 255 | except KeyboardInterrupt: 256 | print("\n脚本已终止,感谢使用!") -------------------------------------------------------------------------------- /.history/auto_phone_fill_20250309070507.py: -------------------------------------------------------------------------------- 1 | import undetected_chromedriver as uc 2 | from selenium.webdriver.common.by import By 3 | from selenium.webdriver.support.ui import WebDriverWait 4 | from selenium.webdriver.support import expected_conditions as EC 5 | from selenium.webdriver.common.action_chains import ActionChains 6 | from selenium.webdriver.common.keys import Keys 7 | import time 8 | import threading 9 | import random 10 | import string 11 | import os 12 | 13 | # 全局变量存储浏览器驱动实例,防止被垃圾回收 14 | browser_drivers = [] 15 | 16 | def random_sleep(min_seconds=0.5, max_seconds=2.0): 17 | """随机睡眠一段时间,模拟人类行为""" 18 | time.sleep(random.uniform(min_seconds, max_seconds)) 19 | 20 | def human_like_typing(element, text): 21 | """模拟人类输入,有随机间隔""" 22 | for char in text: 23 | element.send_keys(char) 24 | # 随机短暂停顿,模拟人类打字速度 25 | time.sleep(random.uniform(0.05, 0.25)) 26 | 27 | def auto_fill_phone(phone_number): 28 | """ 29 | 自动打开SiliconFlow登录页面并填写手机号 30 | 31 | 参数: 32 | phone_number (str): 要填写的手机号码 33 | """ 34 | global browser_drivers 35 | 36 | print(f"开始为手机号 {phone_number} 自动填写表单...") 37 | 38 | # 创建一个临时目录作为用户数据目录,每次使用不同的目录以隔离会话 39 | user_data_dir = f"chrome_user_data_{phone_number}" 40 | 41 | # 确保目录存在 42 | os.makedirs(user_data_dir, exist_ok=True) 43 | 44 | try: 45 | # 使用undetected_chromedriver而不是标准selenium 46 | options = uc.ChromeOptions() 47 | 48 | # 添加随机用户代理 49 | user_agents = [ 50 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36", 51 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.6943.143 Safari/537.36", 52 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0", 53 | "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15", 54 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.6943.143 Safari/537.36 Edg/120.0.0.0" 55 | ] 56 | options.add_argument(f"user-agent={random.choice(user_agents)}") 57 | 58 | # 设置用户数据目录 59 | options.add_argument(f"--user-data-dir={os.path.abspath(user_data_dir)}") 60 | 61 | # 设置首次运行参数,避免显示首次运行对话框 62 | options.add_argument("--no-first-run") 63 | options.add_argument("--no-default-browser-check") 64 | 65 | # 增加随机性,避免指纹追踪 66 | options.add_argument(f"--window-size={random.randint(1000, 1920)},{random.randint(700, 1080)}") 67 | 68 | # 增加会话隐私性 69 | options.add_argument("--incognito") 70 | 71 | # 禁用自动化扩展 72 | options.add_argument("--disable-blink-features=AutomationControlled") 73 | 74 | # 初始化undetected_chromedriver,强制使用与当前Chrome版本兼容的驱动 75 | driver = uc.Chrome( 76 | options=options, 77 | driver_executable_path=None, 78 | headless=False, 79 | version_main=133, # 固定使用Chrome 133版本的驱动 80 | use_subprocess=True, # 使用子进程运行,提高稳定性 81 | ) 82 | 83 | # 将驱动实例添加到全局列表中,防止被垃圾回收 84 | browser_drivers.append(driver) 85 | 86 | # 设置隐式等待 87 | driver.implicitly_wait(10) 88 | 89 | # 打开登录页面 90 | url = "https://account.siliconflow.cn/zh/login?redirect=https%3A%2F%2Fcloud.siliconflow.cn%2F%3F" 91 | driver.get(url) 92 | print(f"已为手机号 {phone_number} 打开登录页面") 93 | 94 | # 随机延迟,模拟人类阅读页面 95 | random_sleep(1.0, 3.0) 96 | 97 | # 模拟人类行为 - 滚动页面 98 | driver.execute_script(f"window.scrollBy(0, {random.randint(100, 300)});") 99 | random_sleep(0.5, 1.5) 100 | driver.execute_script(f"window.scrollBy(0, {random.randint(-100, -50)});") 101 | random_sleep(0.3, 0.8) 102 | 103 | # 尝试找到并填写手机号输入框 104 | try: 105 | # 尝试通过各种选择器找到输入框 106 | selectors = [ 107 | "//input[@placeholder='请输入手机号' or contains(@placeholder, '手机号')]", 108 | "//input[contains(@class, 'phone') or contains(@name, 'phone') or contains(@id, 'phone')]", 109 | "//input[@type='tel']" 110 | ] 111 | 112 | phone_input = None 113 | for selector in selectors: 114 | try: 115 | elements = driver.find_elements(By.XPATH, selector) 116 | if elements: 117 | phone_input = elements[0] 118 | break 119 | except: 120 | continue 121 | 122 | if not phone_input: 123 | print("未找到手机号输入框,尝试查看页面源码...") 124 | print(driver.page_source) 125 | return 126 | 127 | # 鼠标移动到输入框 128 | action = ActionChains(driver) 129 | action.move_to_element(phone_input).perform() 130 | random_sleep(0.3, 0.7) 131 | 132 | # 点击输入框 133 | action.click().perform() 134 | random_sleep(0.2, 0.6) 135 | 136 | # 清空输入框 137 | phone_input.clear() 138 | random_sleep(0.2, 0.4) 139 | 140 | # 模拟人类输入 141 | human_like_typing(phone_input, phone_number) 142 | 143 | print(f"已成功填写手机号: {phone_number}") 144 | 145 | # 随机延迟,模拟人类行为 146 | random_sleep(0.8, 1.5) 147 | 148 | # 可能的后续操作,如按下Tab键或点击获取验证码 149 | if random.choice([True, False]): 150 | action.send_keys(Keys.TAB).perform() 151 | else: 152 | # 尝试查找并点击验证码按钮,但不强制 153 | try: 154 | code_buttons = driver.find_elements(By.XPATH, "//button[contains(text(), '验证码') or contains(text(), '获取')]") 155 | if code_buttons: 156 | # 鼠标移动到按钮 157 | action.move_to_element(code_buttons[0]).perform() 158 | random_sleep(0.3, 0.8) 159 | # 不实际点击,让用户自己点击 160 | except: 161 | pass 162 | 163 | except Exception as e: 164 | print(f"填写手机号时出错: {e}") 165 | 166 | # 如果上面的方法失败,可以尝试打印页面源代码帮助调试 167 | print("页面源代码:") 168 | print(driver.page_source) 169 | 170 | except Exception as e: 171 | print(f"浏览器操作出错: {e}") 172 | 173 | print(f"手机号 {phone_number} 脚本执行完毕") 174 | # 注意:不要在这里调用driver.quit(),保持浏览器打开 175 | 176 | def open_multiple_browsers(phone_numbers): 177 | """ 178 | 同时打开多个浏览器实例并填写不同的手机号 179 | 180 | 参数: 181 | phone_numbers (list): 要填写的手机号列表 182 | """ 183 | threads = [] 184 | 185 | # 为每个手机号创建一个线程 186 | for phone in phone_numbers: 187 | thread = threading.Thread(target=auto_fill_phone, args=(phone,)) 188 | thread.daemon = False # 设置为非守护线程 189 | threads.append(thread) 190 | 191 | # 启动所有线程 192 | for thread in threads: 193 | thread.start() 194 | # 每个浏览器启动间隔随机延迟,更像人类行为 195 | random_sleep(2.0, 5.0) 196 | 197 | # 等待所有线程完成 198 | for thread in threads: 199 | thread.join() 200 | 201 | print("所有浏览器实例已启动并填写完毕") 202 | 203 | def get_user_input_phones(browser_count): 204 | """ 205 | 获取用户输入的手机号 206 | 207 | 参数: 208 | browser_count (int): 需要开启的浏览器数量 209 | 210 | 返回: 211 | list: 用户输入的手机号列表 212 | """ 213 | phone_numbers = [] 214 | print(f"\n请输入{browser_count}个手机号,每个手机号输入完成后按回车确认:") 215 | 216 | for i in range(browser_count): 217 | while True: 218 | phone = input(f"请输入第 {i+1} 个手机号: ") 219 | 220 | # 简单验证手机号格式(11位数字) 221 | if phone.isdigit() and len(phone) == 11: 222 | phone_numbers.append(phone) 223 | break 224 | else: 225 | print("手机号格式不正确,请输入11位数字手机号!") 226 | 227 | print("\n您输入的手机号如下:") 228 | for i, phone in enumerate(phone_numbers): 229 | print(f"{i+1}. {phone}") 230 | 231 | # 移除确认步骤,直接返回手机号列表 232 | return phone_numbers 233 | 234 | if __name__ == "__main__": 235 | # 获取用户输入的浏览器数量 236 | while True: 237 | try: 238 | browser_count = int(input("请输入需要开启的浏览器数量(1-10): ")) 239 | if 1 <= browser_count <= 10: 240 | break 241 | else: 242 | print("请输入1到10之间的数字!") 243 | except ValueError: 244 | print("请输入有效的数字!") 245 | 246 | # 获取用户输入的手机号 247 | phone_numbers = get_user_input_phones(browser_count) 248 | 249 | # 直接运行,不再进行确认 250 | print("\n正在启动浏览器并填写手机号...") 251 | open_multiple_browsers(phone_numbers) 252 | 253 | # 重要:保持脚本运行,防止浏览器关闭 254 | print("\n所有操作已完成。浏览器将保持打开状态。") 255 | print("请按Ctrl+C手动终止此脚本(当您使用完浏览器后)...") 256 | 257 | # 无限循环保持脚本运行 258 | try: 259 | while True: 260 | time.sleep(1000) 261 | except KeyboardInterrupt: 262 | print("\n脚本已终止,感谢使用!") -------------------------------------------------------------------------------- /.history/auto_phone_fill_20250309070511.py: -------------------------------------------------------------------------------- 1 | import undetected_chromedriver as uc 2 | from selenium.webdriver.common.by import By 3 | from selenium.webdriver.support.ui import WebDriverWait 4 | from selenium.webdriver.support import expected_conditions as EC 5 | from selenium.webdriver.common.action_chains import ActionChains 6 | from selenium.webdriver.common.keys import Keys 7 | import time 8 | import threading 9 | import random 10 | import string 11 | import os 12 | 13 | # 全局变量存储浏览器驱动实例,防止被垃圾回收 14 | browser_drivers = [] 15 | 16 | def random_sleep(min_seconds=0.5, max_seconds=2.0): 17 | """随机睡眠一段时间,模拟人类行为""" 18 | time.sleep(random.uniform(min_seconds, max_seconds)) 19 | 20 | def human_like_typing(element, text): 21 | """模拟人类输入,有随机间隔""" 22 | for char in text: 23 | element.send_keys(char) 24 | # 随机短暂停顿,模拟人类打字速度 25 | time.sleep(random.uniform(0.05, 0.25)) 26 | 27 | def auto_fill_phone(phone_number): 28 | """ 29 | 自动打开SiliconFlow登录页面并填写手机号 30 | 31 | 参数: 32 | phone_number (str): 要填写的手机号码 33 | """ 34 | global browser_drivers 35 | 36 | print(f"开始为手机号 {phone_number} 自动填写表单...") 37 | 38 | # 创建一个临时目录作为用户数据目录,每次使用不同的目录以隔离会话 39 | user_data_dir = f"chrome_user_data_{phone_number}" 40 | 41 | # 确保目录存在 42 | os.makedirs(user_data_dir, exist_ok=True) 43 | 44 | try: 45 | # 使用undetected_chromedriver而不是标准selenium 46 | options = uc.ChromeOptions() 47 | 48 | # 添加随机用户代理 49 | user_agents = [ 50 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36", 51 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.6943.143 Safari/537.36", 52 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0", 53 | "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15", 54 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.6943.143 Safari/537.36 Edg/120.0.0.0" 55 | ] 56 | options.add_argument(f"user-agent={random.choice(user_agents)}") 57 | 58 | # 设置用户数据目录 59 | options.add_argument(f"--user-data-dir={os.path.abspath(user_data_dir)}") 60 | 61 | # 设置首次运行参数,避免显示首次运行对话框 62 | options.add_argument("--no-first-run") 63 | options.add_argument("--no-default-browser-check") 64 | 65 | # 增加随机性,避免指纹追踪 66 | options.add_argument(f"--window-size={random.randint(1000, 1920)},{random.randint(700, 1080)}") 67 | 68 | # 增加会话隐私性 69 | options.add_argument("--incognito") 70 | 71 | # 禁用自动化扩展 72 | options.add_argument("--disable-blink-features=AutomationControlled") 73 | 74 | # 初始化undetected_chromedriver,强制使用与当前Chrome版本兼容的驱动 75 | driver = uc.Chrome( 76 | options=options, 77 | driver_executable_path=None, 78 | headless=False, 79 | version_main=133, # 固定使用Chrome 133版本的驱动 80 | use_subprocess=True, # 使用子进程运行,提高稳定性 81 | ) 82 | 83 | # 将驱动实例添加到全局列表中,防止被垃圾回收 84 | browser_drivers.append(driver) 85 | 86 | # 设置隐式等待 87 | driver.implicitly_wait(10) 88 | 89 | # 打开登录页面 90 | url = "https://account.siliconflow.cn/zh/login?redirect=https%3A%2F%2Fcloud.siliconflow.cn%2F%3F" 91 | driver.get(url) 92 | print(f"已为手机号 {phone_number} 打开登录页面") 93 | 94 | # 随机延迟,模拟人类阅读页面 95 | random_sleep(1.0, 3.0) 96 | 97 | # 模拟人类行为 - 滚动页面 98 | driver.execute_script(f"window.scrollBy(0, {random.randint(100, 300)});") 99 | random_sleep(0.5, 1.5) 100 | driver.execute_script(f"window.scrollBy(0, {random.randint(-100, -50)});") 101 | random_sleep(0.3, 0.8) 102 | 103 | # 尝试找到并填写手机号输入框 104 | try: 105 | # 尝试通过各种选择器找到输入框 106 | selectors = [ 107 | "//input[@placeholder='请输入手机号' or contains(@placeholder, '手机号')]", 108 | "//input[contains(@class, 'phone') or contains(@name, 'phone') or contains(@id, 'phone')]", 109 | "//input[@type='tel']" 110 | ] 111 | 112 | phone_input = None 113 | for selector in selectors: 114 | try: 115 | elements = driver.find_elements(By.XPATH, selector) 116 | if elements: 117 | phone_input = elements[0] 118 | break 119 | except: 120 | continue 121 | 122 | if not phone_input: 123 | print("未找到手机号输入框,尝试查看页面源码...") 124 | print(driver.page_source) 125 | return 126 | 127 | # 鼠标移动到输入框 128 | action = ActionChains(driver) 129 | action.move_to_element(phone_input).perform() 130 | random_sleep(0.3, 0.7) 131 | 132 | # 点击输入框 133 | action.click().perform() 134 | random_sleep(0.2, 0.6) 135 | 136 | # 清空输入框 137 | phone_input.clear() 138 | random_sleep(0.2, 0.4) 139 | 140 | # 模拟人类输入 141 | human_like_typing(phone_input, phone_number) 142 | 143 | print(f"已成功填写手机号: {phone_number}") 144 | 145 | # 随机延迟,模拟人类行为 146 | random_sleep(0.8, 1.5) 147 | 148 | # 可能的后续操作,如按下Tab键或点击获取验证码 149 | if random.choice([True, False]): 150 | action.send_keys(Keys.TAB).perform() 151 | else: 152 | # 尝试查找并点击验证码按钮,但不强制 153 | try: 154 | code_buttons = driver.find_elements(By.XPATH, "//button[contains(text(), '验证码') or contains(text(), '获取')]") 155 | if code_buttons: 156 | # 鼠标移动到按钮 157 | action.move_to_element(code_buttons[0]).perform() 158 | random_sleep(0.3, 0.8) 159 | # 不实际点击,让用户自己点击 160 | except: 161 | pass 162 | 163 | except Exception as e: 164 | print(f"填写手机号时出错: {e}") 165 | 166 | # 如果上面的方法失败,可以尝试打印页面源代码帮助调试 167 | print("页面源代码:") 168 | print(driver.page_source) 169 | 170 | except Exception as e: 171 | print(f"浏览器操作出错: {e}") 172 | 173 | print(f"手机号 {phone_number} 脚本执行完毕") 174 | # 注意:不要在这里调用driver.quit(),保持浏览器打开 175 | 176 | def open_multiple_browsers(phone_numbers): 177 | """ 178 | 同时打开多个浏览器实例并填写不同的手机号 179 | 180 | 参数: 181 | phone_numbers (list): 要填写的手机号列表 182 | """ 183 | threads = [] 184 | 185 | # 为每个手机号创建一个线程 186 | for phone in phone_numbers: 187 | thread = threading.Thread(target=auto_fill_phone, args=(phone,)) 188 | thread.daemon = False # 设置为非守护线程 189 | threads.append(thread) 190 | 191 | # 启动所有线程 192 | for thread in threads: 193 | thread.start() 194 | # 每个浏览器启动间隔随机延迟,更像人类行为 195 | random_sleep(2.0, 5.0) 196 | 197 | # 等待所有线程完成 198 | for thread in threads: 199 | thread.join() 200 | 201 | print("所有浏览器实例已启动并填写完毕") 202 | 203 | def get_user_input_phones(browser_count): 204 | """ 205 | 获取用户输入的手机号 206 | 207 | 参数: 208 | browser_count (int): 需要开启的浏览器数量 209 | 210 | 返回: 211 | list: 用户输入的手机号列表 212 | """ 213 | phone_numbers = [] 214 | print(f"\n请输入{browser_count}个手机号,每个手机号输入完成后按回车确认:") 215 | 216 | for i in range(browser_count): 217 | while True: 218 | phone = input(f"请输入第 {i+1} 个手机号: ") 219 | 220 | # 简单验证手机号格式(11位数字) 221 | if phone.isdigit() and len(phone) == 11: 222 | phone_numbers.append(phone) 223 | break 224 | else: 225 | print("手机号格式不正确,请输入11位数字手机号!") 226 | 227 | print("\n您输入的手机号如下:") 228 | for i, phone in enumerate(phone_numbers): 229 | print(f"{i+1}. {phone}") 230 | 231 | # 移除确认步骤,直接返回手机号列表 232 | return phone_numbers 233 | 234 | if __name__ == "__main__": 235 | # 获取用户输入的浏览器数量 236 | while True: 237 | try: 238 | browser_count = int(input("请输入需要开启的浏览器数量(1-10): ")) 239 | if 1 <= browser_count <= 10: 240 | break 241 | else: 242 | print("请输入1到10之间的数字!") 243 | except ValueError: 244 | print("请输入有效的数字!") 245 | 246 | # 获取用户输入的手机号 247 | phone_numbers = get_user_input_phones(browser_count) 248 | 249 | # 直接运行,不再进行确认 250 | print("\n正在启动浏览器并填写手机号...") 251 | open_multiple_browsers(phone_numbers) 252 | 253 | # 重要:保持脚本运行,防止浏览器关闭 254 | print("\n所有操作已完成。浏览器将保持打开状态。") 255 | print("请按Ctrl+C手动终止此脚本(当您使用完浏览器后)...") 256 | 257 | # 无限循环保持脚本运行 258 | try: 259 | while True: 260 | time.sleep(1000) 261 | except KeyboardInterrupt: 262 | print("\n脚本已终止,感谢使用!") -------------------------------------------------------------------------------- /.history/auto_phone_fill_20250309070918.py: -------------------------------------------------------------------------------- 1 | import undetected_chromedriver as uc 2 | from selenium.webdriver.common.by import By 3 | from selenium.webdriver.support.ui import WebDriverWait 4 | from selenium.webdriver.support import expected_conditions as EC 5 | from selenium.webdriver.common.action_chains import ActionChains 6 | from selenium.webdriver.common.keys import Keys 7 | import time 8 | import threading 9 | import random 10 | import string 11 | import os 12 | 13 | # 全局变量存储浏览器驱动实例,防止被垃圾回收 14 | browser_drivers = [] 15 | 16 | def random_sleep(min_seconds=0.5, max_seconds=2.0): 17 | """随机睡眠一段时间,模拟人类行为""" 18 | time.sleep(random.uniform(min_seconds, max_seconds)) 19 | 20 | # 不再使用人类模拟输入方法 21 | # def human_like_typing(element, text): 22 | # """模拟人类输入,有随机间隔""" 23 | # for char in text: 24 | # element.send_keys(char) 25 | # # 随机短暂停顿,模拟人类打字速度 26 | # time.sleep(random.uniform(0.05, 0.25)) 27 | 28 | def auto_fill_phone(phone_number): 29 | """ 30 | 自动打开SiliconFlow登录页面并填写手机号 31 | 32 | 参数: 33 | phone_number (str): 要填写的手机号码 34 | """ 35 | global browser_drivers 36 | 37 | print(f"开始为手机号 {phone_number} 自动填写表单...") 38 | 39 | # 创建一个临时目录作为用户数据目录,每次使用不同的目录以隔离会话 40 | user_data_dir = f"chrome_user_data_{phone_number}" 41 | 42 | # 确保目录存在 43 | os.makedirs(user_data_dir, exist_ok=True) 44 | 45 | try: 46 | # 使用undetected_chromedriver而不是标准selenium 47 | options = uc.ChromeOptions() 48 | 49 | # 添加随机用户代理 50 | user_agents = [ 51 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36", 52 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.6943.143 Safari/537.36", 53 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0", 54 | "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15", 55 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.6943.143 Safari/537.36 Edg/120.0.0.0" 56 | ] 57 | options.add_argument(f"user-agent={random.choice(user_agents)}") 58 | 59 | # 设置用户数据目录 60 | options.add_argument(f"--user-data-dir={os.path.abspath(user_data_dir)}") 61 | 62 | # 设置首次运行参数,避免显示首次运行对话框 63 | options.add_argument("--no-first-run") 64 | options.add_argument("--no-default-browser-check") 65 | 66 | # 增加随机性,避免指纹追踪 67 | options.add_argument(f"--window-size={random.randint(1000, 1920)},{random.randint(700, 1080)}") 68 | 69 | # 增加会话隐私性 70 | options.add_argument("--incognito") 71 | 72 | # 禁用自动化扩展 73 | options.add_argument("--disable-blink-features=AutomationControlled") 74 | 75 | # 初始化undetected_chromedriver,强制使用与当前Chrome版本兼容的驱动 76 | driver = uc.Chrome( 77 | options=options, 78 | driver_executable_path=None, 79 | headless=False, 80 | version_main=133, # 固定使用Chrome 133版本的驱动 81 | use_subprocess=True, # 使用子进程运行,提高稳定性 82 | ) 83 | 84 | # 将驱动实例添加到全局列表中,防止被垃圾回收 85 | browser_drivers.append(driver) 86 | 87 | # 设置隐式等待 88 | driver.implicitly_wait(10) 89 | 90 | # 打开登录页面 91 | url = "https://account.siliconflow.cn/zh/login?redirect=https%3A%2F%2Fcloud.siliconflow.cn%2F%3F" 92 | driver.get(url) 93 | print(f"已为手机号 {phone_number} 打开登录页面") 94 | 95 | # 随机延迟,模拟人类阅读页面 96 | random_sleep(1.0, 2.0) 97 | 98 | # 尝试找到并填写手机号输入框 99 | try: 100 | # 尝试通过各种选择器找到输入框 101 | selectors = [ 102 | "//input[@placeholder='请输入手机号' or contains(@placeholder, '手机号')]", 103 | "//input[contains(@class, 'phone') or contains(@name, 'phone') or contains(@id, 'phone')]", 104 | "//input[@type='tel']" 105 | ] 106 | 107 | phone_input = None 108 | for selector in selectors: 109 | try: 110 | elements = driver.find_elements(By.XPATH, selector) 111 | if elements: 112 | phone_input = elements[0] 113 | break 114 | except: 115 | continue 116 | 117 | if not phone_input: 118 | print("未找到手机号输入框,尝试查看页面源码...") 119 | print(driver.page_source) 120 | return 121 | 122 | # 直接点击输入框 123 | phone_input.click() 124 | 125 | # 清空输入框 126 | phone_input.clear() 127 | 128 | # 直接输入手机号,不再模拟人类输入 129 | phone_input.send_keys(phone_number) 130 | 131 | print(f"已成功填写手机号: {phone_number}") 132 | 133 | # 可能的后续操作,如按下Tab键或点击获取验证码 134 | if random.choice([True, False]): 135 | action = ActionChains(driver) 136 | action.send_keys(Keys.TAB).perform() 137 | else: 138 | # 尝试查找并点击验证码按钮,但不强制 139 | try: 140 | code_buttons = driver.find_elements(By.XPATH, "//button[contains(text(), '验证码') or contains(text(), '获取')]") 141 | if code_buttons: 142 | # 鼠标移动到按钮 143 | action = ActionChains(driver) 144 | action.move_to_element(code_buttons[0]).perform() 145 | except: 146 | pass 147 | 148 | except Exception as e: 149 | print(f"填写手机号时出错: {e}") 150 | 151 | # 如果上面的方法失败,可以尝试打印页面源代码帮助调试 152 | print("页面源代码:") 153 | print(driver.page_source) 154 | 155 | except Exception as e: 156 | print(f"浏览器操作出错: {e}") 157 | 158 | print(f"手机号 {phone_number} 脚本执行完毕") 159 | # 注意:不要在这里调用driver.quit(),保持浏览器打开 160 | 161 | def open_multiple_browsers(phone_numbers): 162 | """ 163 | 同时打开多个浏览器实例并填写不同的手机号 164 | 165 | 参数: 166 | phone_numbers (list): 要填写的手机号列表 167 | """ 168 | threads = [] 169 | 170 | # 为每个手机号创建一个线程 171 | for phone in phone_numbers: 172 | thread = threading.Thread(target=auto_fill_phone, args=(phone,)) 173 | thread.daemon = False # 设置为非守护线程 174 | threads.append(thread) 175 | 176 | # 启动所有线程 177 | for thread in threads: 178 | thread.start() 179 | # 每个浏览器启动间隔随机延迟,更像人类行为 180 | random_sleep(2.0, 3.0) 181 | 182 | # 等待所有线程完成 183 | for thread in threads: 184 | thread.join() 185 | 186 | print("所有浏览器实例已启动并填写完毕") 187 | 188 | def get_user_input_phones(browser_count): 189 | """ 190 | 获取用户输入的手机号 191 | 192 | 参数: 193 | browser_count (int): 需要开启的浏览器数量 194 | 195 | 返回: 196 | list: 用户输入的手机号列表 197 | """ 198 | phone_numbers = [] 199 | print(f"\n请输入{browser_count}个手机号,每个手机号输入完成后按回车确认:") 200 | 201 | for i in range(browser_count): 202 | while True: 203 | phone = input(f"请输入第 {i+1} 个手机号: ") 204 | 205 | # 简单验证手机号格式(11位数字) 206 | if phone.isdigit() and len(phone) == 11: 207 | phone_numbers.append(phone) 208 | break 209 | else: 210 | print("手机号格式不正确,请输入11位数字手机号!") 211 | 212 | print("\n您输入的手机号如下:") 213 | for i, phone in enumerate(phone_numbers): 214 | print(f"{i+1}. {phone}") 215 | 216 | # 移除确认步骤,直接返回手机号列表 217 | return phone_numbers 218 | 219 | if __name__ == "__main__": 220 | # 获取用户输入的浏览器数量 221 | while True: 222 | try: 223 | browser_count = int(input("请输入需要开启的浏览器数量(1-10): ")) 224 | if 1 <= browser_count <= 10: 225 | break 226 | else: 227 | print("请输入1到10之间的数字!") 228 | except ValueError: 229 | print("请输入有效的数字!") 230 | 231 | # 获取用户输入的手机号 232 | phone_numbers = get_user_input_phones(browser_count) 233 | 234 | # 直接运行,不再进行确认 235 | print("\n正在启动浏览器并填写手机号...") 236 | open_multiple_browsers(phone_numbers) 237 | 238 | # 重要:保持脚本运行,防止浏览器关闭 239 | print("\n所有操作已完成。浏览器将保持打开状态。") 240 | print("请按Ctrl+C手动终止此脚本(当您使用完浏览器后)...") 241 | 242 | # 无限循环保持脚本运行 243 | try: 244 | while True: 245 | time.sleep(1000) 246 | except KeyboardInterrupt: 247 | print("\n脚本已终止,感谢使用!") -------------------------------------------------------------------------------- /.history/auto_phone_fill_20250309070953.py: -------------------------------------------------------------------------------- 1 | import undetected_chromedriver as uc 2 | from selenium.webdriver.common.by import By 3 | from selenium.webdriver.support.ui import WebDriverWait 4 | from selenium.webdriver.support import expected_conditions as EC 5 | from selenium.webdriver.common.action_chains import ActionChains 6 | from selenium.webdriver.common.keys import Keys 7 | import time 8 | import threading 9 | import random 10 | import string 11 | import os 12 | 13 | # 全局变量存储浏览器驱动实例,防止被垃圾回收 14 | browser_drivers = [] 15 | 16 | def random_sleep(min_seconds=0.5, max_seconds=2.0): 17 | """随机睡眠一段时间,模拟人类行为""" 18 | time.sleep(random.uniform(min_seconds, max_seconds)) 19 | 20 | # 不再使用人类模拟输入方法 21 | # def human_like_typing(element, text): 22 | # """模拟人类输入,有随机间隔""" 23 | # for char in text: 24 | # element.send_keys(char) 25 | # # 随机短暂停顿,模拟人类打字速度 26 | # time.sleep(random.uniform(0.05, 0.25)) 27 | 28 | def auto_fill_phone(phone_number): 29 | """ 30 | 自动打开SiliconFlow登录页面并填写手机号 31 | 32 | 参数: 33 | phone_number (str): 要填写的手机号码 34 | """ 35 | global browser_drivers 36 | 37 | print(f"开始为手机号 {phone_number} 自动填写表单...") 38 | 39 | # 创建一个临时目录作为用户数据目录,每次使用不同的目录以隔离会话 40 | user_data_dir = f"chrome_user_data_{phone_number}" 41 | 42 | # 确保目录存在 43 | os.makedirs(user_data_dir, exist_ok=True) 44 | 45 | try: 46 | # 使用undetected_chromedriver而不是标准selenium 47 | options = uc.ChromeOptions() 48 | 49 | # 添加随机用户代理 50 | user_agents = [ 51 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36", 52 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.6943.143 Safari/537.36", 53 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0", 54 | "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15", 55 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.6943.143 Safari/537.36 Edg/120.0.0.0" 56 | ] 57 | options.add_argument(f"user-agent={random.choice(user_agents)}") 58 | 59 | # 设置用户数据目录 60 | options.add_argument(f"--user-data-dir={os.path.abspath(user_data_dir)}") 61 | 62 | # 设置首次运行参数,避免显示首次运行对话框 63 | options.add_argument("--no-first-run") 64 | options.add_argument("--no-default-browser-check") 65 | 66 | # 增加随机性,避免指纹追踪 67 | options.add_argument(f"--window-size={random.randint(1000, 1920)},{random.randint(700, 1080)}") 68 | 69 | # 增加会话隐私性 70 | options.add_argument("--incognito") 71 | 72 | # 禁用自动化扩展 73 | options.add_argument("--disable-blink-features=AutomationControlled") 74 | 75 | # 初始化undetected_chromedriver,强制使用与当前Chrome版本兼容的驱动 76 | driver = uc.Chrome( 77 | options=options, 78 | driver_executable_path=None, 79 | headless=False, 80 | version_main=133, # 固定使用Chrome 133版本的驱动 81 | use_subprocess=True, # 使用子进程运行,提高稳定性 82 | ) 83 | 84 | # 将驱动实例添加到全局列表中,防止被垃圾回收 85 | browser_drivers.append(driver) 86 | 87 | # 设置隐式等待 88 | driver.implicitly_wait(10) 89 | 90 | # 打开登录页面 91 | url = "https://account.siliconflow.cn/zh/login?redirect=https%3A%2F%2Fcloud.siliconflow.cn%2F%3F" 92 | driver.get(url) 93 | print(f"已为手机号 {phone_number} 打开登录页面") 94 | 95 | # 随机延迟,模拟人类阅读页面 96 | random_sleep(1.0, 2.0) 97 | 98 | # 尝试找到并填写手机号输入框 99 | try: 100 | # 尝试通过各种选择器找到输入框 101 | selectors = [ 102 | "//input[@placeholder='请输入手机号' or contains(@placeholder, '手机号')]", 103 | "//input[contains(@class, 'phone') or contains(@name, 'phone') or contains(@id, 'phone')]", 104 | "//input[@type='tel']" 105 | ] 106 | 107 | phone_input = None 108 | for selector in selectors: 109 | try: 110 | elements = driver.find_elements(By.XPATH, selector) 111 | if elements: 112 | phone_input = elements[0] 113 | break 114 | except: 115 | continue 116 | 117 | if not phone_input: 118 | print("未找到手机号输入框,尝试查看页面源码...") 119 | print(driver.page_source) 120 | return 121 | 122 | # 直接点击输入框 123 | phone_input.click() 124 | 125 | # 清空输入框 126 | phone_input.clear() 127 | 128 | # 直接输入手机号,不再模拟人类输入 129 | phone_input.send_keys(phone_number) 130 | 131 | print(f"已成功填写手机号: {phone_number}") 132 | 133 | # 可能的后续操作,如按下Tab键或点击获取验证码 134 | if random.choice([True, False]): 135 | action = ActionChains(driver) 136 | action.send_keys(Keys.TAB).perform() 137 | else: 138 | # 尝试查找并点击验证码按钮,但不强制 139 | try: 140 | code_buttons = driver.find_elements(By.XPATH, "//button[contains(text(), '验证码') or contains(text(), '获取')]") 141 | if code_buttons: 142 | # 鼠标移动到按钮 143 | action = ActionChains(driver) 144 | action.move_to_element(code_buttons[0]).perform() 145 | except: 146 | pass 147 | 148 | except Exception as e: 149 | print(f"填写手机号时出错: {e}") 150 | 151 | # 如果上面的方法失败,可以尝试打印页面源代码帮助调试 152 | print("页面源代码:") 153 | print(driver.page_source) 154 | 155 | except Exception as e: 156 | print(f"浏览器操作出错: {e}") 157 | 158 | print(f"手机号 {phone_number} 脚本执行完毕") 159 | # 注意:不要在这里调用driver.quit(),保持浏览器打开 160 | 161 | def open_multiple_browsers(phone_numbers): 162 | """ 163 | 同时打开多个浏览器实例并填写不同的手机号 164 | 165 | 参数: 166 | phone_numbers (list): 要填写的手机号列表 167 | """ 168 | threads = [] 169 | 170 | # 为每个手机号创建一个线程 171 | for phone in phone_numbers: 172 | thread = threading.Thread(target=auto_fill_phone, args=(phone,)) 173 | thread.daemon = False # 设置为非守护线程 174 | threads.append(thread) 175 | 176 | # 启动所有线程 177 | for thread in threads: 178 | thread.start() 179 | # 每个浏览器启动间隔随机延迟,更像人类行为 180 | random_sleep(2.0, 3.0) 181 | 182 | # 等待所有线程完成 183 | for thread in threads: 184 | thread.join() 185 | 186 | print("所有浏览器实例已启动并填写完毕") 187 | 188 | def get_user_input_phones(browser_count): 189 | """ 190 | 获取用户输入的手机号 191 | 192 | 参数: 193 | browser_count (int): 需要开启的浏览器数量 194 | 195 | 返回: 196 | list: 用户输入的手机号列表 197 | """ 198 | phone_numbers = [] 199 | print(f"\n请输入{browser_count}个手机号,每个手机号输入完成后按回车确认:") 200 | 201 | for i in range(browser_count): 202 | while True: 203 | phone = input(f"请输入第 {i+1} 个手机号: ") 204 | 205 | # 简单验证手机号格式(11位数字) 206 | if phone.isdigit() and len(phone) == 11: 207 | phone_numbers.append(phone) 208 | break 209 | else: 210 | print("手机号格式不正确,请输入11位数字手机号!") 211 | 212 | print("\n您输入的手机号如下:") 213 | for i, phone in enumerate(phone_numbers): 214 | print(f"{i+1}. {phone}") 215 | 216 | # 移除确认步骤,直接返回手机号列表 217 | return phone_numbers 218 | 219 | if __name__ == "__main__": 220 | # 获取用户输入的浏览器数量 221 | while True: 222 | try: 223 | browser_count = int(input("请输入需要开启的浏览器数量(1-10): ")) 224 | if 1 <= browser_count <= 10: 225 | break 226 | else: 227 | print("请输入1到10之间的数字!") 228 | except ValueError: 229 | print("请输入有效的数字!") 230 | 231 | # 获取用户输入的手机号 232 | phone_numbers = get_user_input_phones(browser_count) 233 | 234 | # 直接运行,不再进行确认 235 | print("\n正在启动浏览器并填写手机号...") 236 | open_multiple_browsers(phone_numbers) 237 | 238 | # 重要:保持脚本运行,防止浏览器关闭 239 | print("\n所有操作已完成。浏览器将保持打开状态。") 240 | print("请按Ctrl+C手动终止此脚本(当您使用完浏览器后)...") 241 | 242 | # 无限循环保持脚本运行 243 | try: 244 | while True: 245 | time.sleep(1000) 246 | except KeyboardInterrupt: 247 | print("\n脚本已终止,感谢使用!") -------------------------------------------------------------------------------- /.history/auto_phone_fill_20250309071308.py: -------------------------------------------------------------------------------- 1 | import undetected_chromedriver as uc 2 | from selenium.webdriver.common.by import By 3 | from selenium.webdriver.support.ui import WebDriverWait 4 | from selenium.webdriver.support import expected_conditions as EC 5 | from selenium.webdriver.common.action_chains import ActionChains 6 | from selenium.webdriver.common.keys import Keys 7 | import time 8 | import threading 9 | import random 10 | import string 11 | import os 12 | import re 13 | 14 | # 全局变量存储浏览器驱动实例,防止被垃圾回收 15 | browser_drivers = [] 16 | 17 | def random_sleep(min_seconds=0.5, max_seconds=2.0): 18 | """随机睡眠一段时间,模拟人类行为""" 19 | time.sleep(random.uniform(min_seconds, max_seconds)) 20 | 21 | # 不再使用人类模拟输入方法 22 | # def human_like_typing(element, text): 23 | # """模拟人类输入,有随机间隔""" 24 | # for char in text: 25 | # element.send_keys(char) 26 | # # 随机短暂停顿,模拟人类打字速度 27 | # time.sleep(random.uniform(0.05, 0.25)) 28 | 29 | def auto_fill_phone(phone_number): 30 | """ 31 | 自动打开SiliconFlow登录页面并填写手机号 32 | 33 | 参数: 34 | phone_number (str): 要填写的手机号码 35 | """ 36 | global browser_drivers 37 | 38 | print(f"开始为手机号 {phone_number} 自动填写表单...") 39 | 40 | # 创建一个临时目录作为用户数据目录,每次使用不同的目录以隔离会话 41 | user_data_dir = f"chrome_user_data_{phone_number}" 42 | 43 | # 确保目录存在 44 | os.makedirs(user_data_dir, exist_ok=True) 45 | 46 | try: 47 | # 使用undetected_chromedriver而不是标准selenium 48 | options = uc.ChromeOptions() 49 | 50 | # 添加随机用户代理 51 | user_agents = [ 52 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36", 53 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.6943.143 Safari/537.36", 54 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0", 55 | "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15", 56 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.6943.143 Safari/537.36 Edg/120.0.0.0" 57 | ] 58 | options.add_argument(f"user-agent={random.choice(user_agents)}") 59 | 60 | # 设置用户数据目录 61 | options.add_argument(f"--user-data-dir={os.path.abspath(user_data_dir)}") 62 | 63 | # 设置首次运行参数,避免显示首次运行对话框 64 | options.add_argument("--no-first-run") 65 | options.add_argument("--no-default-browser-check") 66 | 67 | # 增加随机性,避免指纹追踪 68 | options.add_argument(f"--window-size={random.randint(1000, 1920)},{random.randint(700, 1080)}") 69 | 70 | # 增加会话隐私性 71 | options.add_argument("--incognito") 72 | 73 | # 禁用自动化扩展 74 | options.add_argument("--disable-blink-features=AutomationControlled") 75 | 76 | # 初始化undetected_chromedriver,强制使用与当前Chrome版本兼容的驱动 77 | driver = uc.Chrome( 78 | options=options, 79 | driver_executable_path=None, 80 | headless=False, 81 | version_main=133, # 固定使用Chrome 133版本的驱动 82 | use_subprocess=True, # 使用子进程运行,提高稳定性 83 | ) 84 | 85 | # 将驱动实例添加到全局列表中,防止被垃圾回收 86 | browser_drivers.append(driver) 87 | 88 | # 设置隐式等待 89 | driver.implicitly_wait(10) 90 | 91 | # 打开登录页面 92 | url = "https://account.siliconflow.cn/zh/login?redirect=https%3A%2F%2Fcloud.siliconflow.cn%2F%3F" 93 | driver.get(url) 94 | print(f"已为手机号 {phone_number} 打开登录页面") 95 | 96 | # 随机延迟,模拟人类阅读页面 97 | random_sleep(1.0, 2.0) 98 | 99 | # 尝试找到并填写手机号输入框 100 | try: 101 | # 尝试通过各种选择器找到输入框 102 | selectors = [ 103 | "//input[@placeholder='请输入手机号' or contains(@placeholder, '手机号')]", 104 | "//input[contains(@class, 'phone') or contains(@name, 'phone') or contains(@id, 'phone')]", 105 | "//input[@type='tel']" 106 | ] 107 | 108 | phone_input = None 109 | for selector in selectors: 110 | try: 111 | elements = driver.find_elements(By.XPATH, selector) 112 | if elements: 113 | phone_input = elements[0] 114 | break 115 | except: 116 | continue 117 | 118 | if not phone_input: 119 | print("未找到手机号输入框,尝试查看页面源码...") 120 | print(driver.page_source) 121 | return 122 | 123 | # 直接点击输入框 124 | phone_input.click() 125 | 126 | # 清空输入框 127 | phone_input.clear() 128 | 129 | # 直接输入手机号,不再模拟人类输入 130 | phone_input.send_keys(phone_number) 131 | 132 | print(f"已成功填写手机号: {phone_number}") 133 | 134 | # 可能的后续操作,如按下Tab键或点击获取验证码 135 | if random.choice([True, False]): 136 | action = ActionChains(driver) 137 | action.send_keys(Keys.TAB).perform() 138 | else: 139 | # 尝试查找并点击验证码按钮,但不强制 140 | try: 141 | code_buttons = driver.find_elements(By.XPATH, "//button[contains(text(), '验证码') or contains(text(), '获取')]") 142 | if code_buttons: 143 | # 鼠标移动到按钮 144 | action = ActionChains(driver) 145 | action.move_to_element(code_buttons[0]).perform() 146 | except: 147 | pass 148 | 149 | except Exception as e: 150 | print(f"填写手机号时出错: {e}") 151 | 152 | # 如果上面的方法失败,可以尝试打印页面源代码帮助调试 153 | print("页面源代码:") 154 | print(driver.page_source) 155 | 156 | except Exception as e: 157 | print(f"浏览器操作出错: {e}") 158 | 159 | print(f"手机号 {phone_number} 脚本执行完毕") 160 | # 注意:不要在这里调用driver.quit(),保持浏览器打开 161 | 162 | def open_multiple_browsers(phone_numbers): 163 | """ 164 | 同时打开多个浏览器实例并填写不同的手机号 165 | 166 | 参数: 167 | phone_numbers (list): 要填写的手机号列表 168 | """ 169 | threads = [] 170 | 171 | # 为每个手机号创建一个线程 172 | for phone in phone_numbers: 173 | thread = threading.Thread(target=auto_fill_phone, args=(phone,)) 174 | thread.daemon = False # 设置为非守护线程 175 | threads.append(thread) 176 | 177 | # 启动所有线程 178 | for thread in threads: 179 | thread.start() 180 | # 每个浏览器启动间隔随机延迟,更像人类行为 181 | random_sleep(2.0, 3.0) 182 | 183 | # 等待所有线程完成 184 | for thread in threads: 185 | thread.join() 186 | 187 | print("所有浏览器实例已启动并填写完毕") 188 | 189 | def extract_phone_numbers(text): 190 | """ 191 | 从提供的文本中提取手机号 192 | 193 | 参数: 194 | text (str): 包含手机号的文本 195 | 196 | 返回: 197 | list: 提取到的手机号列表 198 | """ 199 | # 中国手机号正则表达式模式(匹配11位数字) 200 | pattern = r'1[3-9]\d{9}' 201 | 202 | # 找出所有匹配的手机号 203 | phone_numbers = re.findall(pattern, text) 204 | 205 | # 去除重复的手机号 206 | unique_numbers = list(set(phone_numbers)) 207 | 208 | return unique_numbers 209 | 210 | if __name__ == "__main__": 211 | print("手机号批量填写工具") 212 | print("请粘贴包含手机号的文本,程序将自动提取并打开浏览器填写:") 213 | print("(输入完成后按两次回车确认)") 214 | 215 | # 收集用户输入直到遇到空行 216 | lines = [] 217 | while True: 218 | line = input() 219 | if not line: # 如果是空行 220 | break 221 | lines.append(line) 222 | 223 | # 将所有行合并为一个文本 224 | input_text = "\n".join(lines) 225 | 226 | # 从文本中提取手机号 227 | phone_numbers = extract_phone_numbers(input_text) 228 | 229 | # 检查是否找到手机号 230 | if not phone_numbers: 231 | print("未在输入文本中找到有效的手机号!") 232 | exit(1) 233 | 234 | # 显示找到的手机号 235 | print(f"\n成功提取到 {len(phone_numbers)} 个手机号:") 236 | for i, phone in enumerate(phone_numbers): 237 | print(f"{i+1}. {phone}") 238 | 239 | # 询问用户是否继续 240 | confirm = input("\n是否使用这些手机号启动浏览器? (y/n): ") 241 | if confirm.lower() != 'y': 242 | print("已取消操作。") 243 | exit(0) 244 | 245 | # 直接运行,不再进行确认 246 | print(f"\n正在启动 {len(phone_numbers)} 个浏览器并填写手机号...") 247 | open_multiple_browsers(phone_numbers) 248 | 249 | # 重要:保持脚本运行,防止浏览器关闭 250 | print("\n所有操作已完成。浏览器将保持打开状态。") 251 | print("请按Ctrl+C手动终止此脚本(当您使用完浏览器后)...") 252 | 253 | # 无限循环保持脚本运行 254 | try: 255 | while True: 256 | time.sleep(1000) 257 | except KeyboardInterrupt: 258 | print("\n脚本已终止,感谢使用!") -------------------------------------------------------------------------------- /.history/auto_phone_fill_20250309071400.py: -------------------------------------------------------------------------------- 1 | import undetected_chromedriver as uc 2 | from selenium.webdriver.common.by import By 3 | from selenium.webdriver.support.ui import WebDriverWait 4 | from selenium.webdriver.support import expected_conditions as EC 5 | from selenium.webdriver.common.action_chains import ActionChains 6 | from selenium.webdriver.common.keys import Keys 7 | import time 8 | import threading 9 | import random 10 | import string 11 | import os 12 | import re 13 | 14 | # 全局变量存储浏览器驱动实例,防止被垃圾回收 15 | browser_drivers = [] 16 | 17 | def random_sleep(min_seconds=0.5, max_seconds=2.0): 18 | """随机睡眠一段时间,模拟人类行为""" 19 | time.sleep(random.uniform(min_seconds, max_seconds)) 20 | 21 | # 不再使用人类模拟输入方法 22 | # def human_like_typing(element, text): 23 | # """模拟人类输入,有随机间隔""" 24 | # for char in text: 25 | # element.send_keys(char) 26 | # # 随机短暂停顿,模拟人类打字速度 27 | # time.sleep(random.uniform(0.05, 0.25)) 28 | 29 | def auto_fill_phone(phone_number): 30 | """ 31 | 自动打开SiliconFlow登录页面并填写手机号 32 | 33 | 参数: 34 | phone_number (str): 要填写的手机号码 35 | """ 36 | global browser_drivers 37 | 38 | print(f"开始为手机号 {phone_number} 自动填写表单...") 39 | 40 | # 创建一个临时目录作为用户数据目录,每次使用不同的目录以隔离会话 41 | user_data_dir = f"chrome_user_data_{phone_number}" 42 | 43 | # 确保目录存在 44 | os.makedirs(user_data_dir, exist_ok=True) 45 | 46 | try: 47 | # 使用undetected_chromedriver而不是标准selenium 48 | options = uc.ChromeOptions() 49 | 50 | # 添加随机用户代理 51 | user_agents = [ 52 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36", 53 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.6943.143 Safari/537.36", 54 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0", 55 | "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15", 56 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.6943.143 Safari/537.36 Edg/120.0.0.0" 57 | ] 58 | options.add_argument(f"user-agent={random.choice(user_agents)}") 59 | 60 | # 设置用户数据目录 61 | options.add_argument(f"--user-data-dir={os.path.abspath(user_data_dir)}") 62 | 63 | # 设置首次运行参数,避免显示首次运行对话框 64 | options.add_argument("--no-first-run") 65 | options.add_argument("--no-default-browser-check") 66 | 67 | # 增加随机性,避免指纹追踪 68 | options.add_argument(f"--window-size={random.randint(1000, 1920)},{random.randint(700, 1080)}") 69 | 70 | # 增加会话隐私性 71 | options.add_argument("--incognito") 72 | 73 | # 禁用自动化扩展 74 | options.add_argument("--disable-blink-features=AutomationControlled") 75 | 76 | # 初始化undetected_chromedriver,强制使用与当前Chrome版本兼容的驱动 77 | driver = uc.Chrome( 78 | options=options, 79 | driver_executable_path=None, 80 | headless=False, 81 | version_main=133, # 固定使用Chrome 133版本的驱动 82 | use_subprocess=True, # 使用子进程运行,提高稳定性 83 | ) 84 | 85 | # 将驱动实例添加到全局列表中,防止被垃圾回收 86 | browser_drivers.append(driver) 87 | 88 | # 设置隐式等待 89 | driver.implicitly_wait(10) 90 | 91 | # 打开登录页面 92 | url = "https://account.siliconflow.cn/zh/login?redirect=https%3A%2F%2Fcloud.siliconflow.cn%2F%3F" 93 | driver.get(url) 94 | print(f"已为手机号 {phone_number} 打开登录页面") 95 | 96 | # 随机延迟,模拟人类阅读页面 97 | random_sleep(1.0, 2.0) 98 | 99 | # 尝试找到并填写手机号输入框 100 | try: 101 | # 尝试通过各种选择器找到输入框 102 | selectors = [ 103 | "//input[@placeholder='请输入手机号' or contains(@placeholder, '手机号')]", 104 | "//input[contains(@class, 'phone') or contains(@name, 'phone') or contains(@id, 'phone')]", 105 | "//input[@type='tel']" 106 | ] 107 | 108 | phone_input = None 109 | for selector in selectors: 110 | try: 111 | elements = driver.find_elements(By.XPATH, selector) 112 | if elements: 113 | phone_input = elements[0] 114 | break 115 | except: 116 | continue 117 | 118 | if not phone_input: 119 | print("未找到手机号输入框,尝试查看页面源码...") 120 | print(driver.page_source) 121 | return 122 | 123 | # 直接点击输入框 124 | phone_input.click() 125 | 126 | # 清空输入框 127 | phone_input.clear() 128 | 129 | # 直接输入手机号,不再模拟人类输入 130 | phone_input.send_keys(phone_number) 131 | 132 | print(f"已成功填写手机号: {phone_number}") 133 | 134 | # 可能的后续操作,如按下Tab键或点击获取验证码 135 | if random.choice([True, False]): 136 | action = ActionChains(driver) 137 | action.send_keys(Keys.TAB).perform() 138 | else: 139 | # 尝试查找并点击验证码按钮,但不强制 140 | try: 141 | code_buttons = driver.find_elements(By.XPATH, "//button[contains(text(), '验证码') or contains(text(), '获取')]") 142 | if code_buttons: 143 | # 鼠标移动到按钮 144 | action = ActionChains(driver) 145 | action.move_to_element(code_buttons[0]).perform() 146 | except: 147 | pass 148 | 149 | except Exception as e: 150 | print(f"填写手机号时出错: {e}") 151 | 152 | # 如果上面的方法失败,可以尝试打印页面源代码帮助调试 153 | print("页面源代码:") 154 | print(driver.page_source) 155 | 156 | except Exception as e: 157 | print(f"浏览器操作出错: {e}") 158 | 159 | print(f"手机号 {phone_number} 脚本执行完毕") 160 | # 注意:不要在这里调用driver.quit(),保持浏览器打开 161 | 162 | def open_multiple_browsers(phone_numbers): 163 | """ 164 | 同时打开多个浏览器实例并填写不同的手机号 165 | 166 | 参数: 167 | phone_numbers (list): 要填写的手机号列表 168 | """ 169 | threads = [] 170 | 171 | # 为每个手机号创建一个线程 172 | for phone in phone_numbers: 173 | thread = threading.Thread(target=auto_fill_phone, args=(phone,)) 174 | thread.daemon = False # 设置为非守护线程 175 | threads.append(thread) 176 | 177 | # 启动所有线程 178 | for thread in threads: 179 | thread.start() 180 | # 每个浏览器启动间隔随机延迟,更像人类行为 181 | random_sleep(2.0, 3.0) 182 | 183 | # 等待所有线程完成 184 | for thread in threads: 185 | thread.join() 186 | 187 | print("所有浏览器实例已启动并填写完毕") 188 | 189 | def extract_phone_numbers(text): 190 | """ 191 | 从提供的文本中提取手机号 192 | 193 | 参数: 194 | text (str): 包含手机号的文本 195 | 196 | 返回: 197 | list: 提取到的手机号列表 198 | """ 199 | # 中国手机号正则表达式模式(匹配11位数字) 200 | pattern = r'1[3-9]\d{9}' 201 | 202 | # 找出所有匹配的手机号 203 | phone_numbers = re.findall(pattern, text) 204 | 205 | # 去除重复的手机号 206 | unique_numbers = list(set(phone_numbers)) 207 | 208 | return unique_numbers 209 | 210 | if __name__ == "__main__": 211 | print("手机号批量填写工具") 212 | print("请粘贴包含手机号的文本,程序将自动提取并打开浏览器填写:") 213 | print("(输入完成后按两次回车确认)") 214 | 215 | # 收集用户输入直到遇到空行 216 | lines = [] 217 | while True: 218 | line = input() 219 | if not line: # 如果是空行 220 | break 221 | lines.append(line) 222 | 223 | # 将所有行合并为一个文本 224 | input_text = "\n".join(lines) 225 | 226 | # 从文本中提取手机号 227 | phone_numbers = extract_phone_numbers(input_text) 228 | 229 | # 检查是否找到手机号 230 | if not phone_numbers: 231 | print("未在输入文本中找到有效的手机号!") 232 | exit(1) 233 | 234 | # 显示找到的手机号 235 | print(f"\n成功提取到 {len(phone_numbers)} 个手机号:") 236 | for i, phone in enumerate(phone_numbers): 237 | print(f"{i+1}. {phone}") 238 | 239 | # 询问用户是否继续 240 | confirm = input("\n是否使用这些手机号启动浏览器? (y/n): ") 241 | if confirm.lower() != 'y': 242 | print("已取消操作。") 243 | exit(0) 244 | 245 | # 直接运行,不再进行确认 246 | print(f"\n正在启动 {len(phone_numbers)} 个浏览器并填写手机号...") 247 | open_multiple_browsers(phone_numbers) 248 | 249 | # 重要:保持脚本运行,防止浏览器关闭 250 | print("\n所有操作已完成。浏览器将保持打开状态。") 251 | print("请按Ctrl+C手动终止此脚本(当您使用完浏览器后)...") 252 | 253 | # 无限循环保持脚本运行 254 | try: 255 | while True: 256 | time.sleep(1000) 257 | except KeyboardInterrupt: 258 | print("\n脚本已终止,感谢使用!") -------------------------------------------------------------------------------- /.history/auto_phone_fill_20250309071633.py: -------------------------------------------------------------------------------- 1 | import undetected_chromedriver as uc 2 | from selenium.webdriver.common.by import By 3 | from selenium.webdriver.support.ui import WebDriverWait 4 | from selenium.webdriver.support import expected_conditions as EC 5 | from selenium.webdriver.common.action_chains import ActionChains 6 | from selenium.webdriver.common.keys import Keys 7 | import time 8 | import threading 9 | import random 10 | import string 11 | import os 12 | import re 13 | 14 | # 全局变量存储浏览器驱动实例,防止被垃圾回收 15 | browser_drivers = [] 16 | 17 | def random_sleep(min_seconds=0.5, max_seconds=2.0): 18 | """随机睡眠一段时间,模拟人类行为""" 19 | time.sleep(random.uniform(min_seconds, max_seconds)) 20 | 21 | # 不再使用人类模拟输入方法 22 | # def human_like_typing(element, text): 23 | # """模拟人类输入,有随机间隔""" 24 | # for char in text: 25 | # element.send_keys(char) 26 | # # 随机短暂停顿,模拟人类打字速度 27 | # time.sleep(random.uniform(0.05, 0.25)) 28 | 29 | def auto_fill_phone(phone_number): 30 | """ 31 | 自动打开SiliconFlow登录页面并填写手机号 32 | 33 | 参数: 34 | phone_number (str): 要填写的手机号码 35 | """ 36 | global browser_drivers 37 | 38 | print(f"开始为手机号 {phone_number} 自动填写表单...") 39 | 40 | # 创建一个临时目录作为用户数据目录,每次使用不同的目录以隔离会话 41 | user_data_dir = f"chrome_user_data_{phone_number}" 42 | 43 | # 确保目录存在 44 | os.makedirs(user_data_dir, exist_ok=True) 45 | 46 | try: 47 | # 使用undetected_chromedriver而不是标准selenium 48 | options = uc.ChromeOptions() 49 | 50 | # 添加随机用户代理 51 | user_agents = [ 52 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36", 53 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.6943.143 Safari/537.36", 54 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0", 55 | "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15", 56 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.6943.143 Safari/537.36 Edg/120.0.0.0" 57 | ] 58 | options.add_argument(f"user-agent={random.choice(user_agents)}") 59 | 60 | # 设置用户数据目录 61 | options.add_argument(f"--user-data-dir={os.path.abspath(user_data_dir)}") 62 | 63 | # 设置首次运行参数,避免显示首次运行对话框 64 | options.add_argument("--no-first-run") 65 | options.add_argument("--no-default-browser-check") 66 | 67 | # 增加随机性,避免指纹追踪 68 | options.add_argument(f"--window-size={random.randint(1000, 1920)},{random.randint(700, 1080)}") 69 | 70 | # 增加会话隐私性 71 | options.add_argument("--incognito") 72 | 73 | # 禁用自动化扩展 74 | options.add_argument("--disable-blink-features=AutomationControlled") 75 | 76 | # 初始化undetected_chromedriver,强制使用与当前Chrome版本兼容的驱动 77 | driver = uc.Chrome( 78 | options=options, 79 | driver_executable_path=None, 80 | headless=False, 81 | version_main=133, # 固定使用Chrome 133版本的驱动 82 | use_subprocess=True, # 使用子进程运行,提高稳定性 83 | ) 84 | 85 | # 将驱动实例添加到全局列表中,防止被垃圾回收 86 | browser_drivers.append(driver) 87 | 88 | # 设置隐式等待 89 | driver.implicitly_wait(10) 90 | 91 | # 打开登录页面 92 | url = "https://account.siliconflow.cn/zh/login?redirect=https%3A%2F%2Fcloud.siliconflow.cn%2F%3F" 93 | driver.get(url) 94 | print(f"已为手机号 {phone_number} 打开登录页面") 95 | 96 | # 随机延迟,模拟人类阅读页面 97 | random_sleep(1.0, 2.0) 98 | 99 | # 尝试找到并填写手机号输入框 100 | try: 101 | # 尝试通过各种选择器找到输入框 102 | selectors = [ 103 | "//input[@placeholder='请输入手机号' or contains(@placeholder, '手机号')]", 104 | "//input[contains(@class, 'phone') or contains(@name, 'phone') or contains(@id, 'phone')]", 105 | "//input[@type='tel']" 106 | ] 107 | 108 | phone_input = None 109 | for selector in selectors: 110 | try: 111 | elements = driver.find_elements(By.XPATH, selector) 112 | if elements: 113 | phone_input = elements[0] 114 | break 115 | except: 116 | continue 117 | 118 | if not phone_input: 119 | print("未找到手机号输入框,尝试查看页面源码...") 120 | print(driver.page_source) 121 | return 122 | 123 | # 直接点击输入框 124 | phone_input.click() 125 | 126 | # 清空输入框 127 | phone_input.clear() 128 | 129 | # 直接输入手机号,不再模拟人类输入 130 | phone_input.send_keys(phone_number) 131 | 132 | print(f"已成功填写手机号: {phone_number}") 133 | 134 | # 可能的后续操作,如按下Tab键或点击获取验证码 135 | if random.choice([True, False]): 136 | action = ActionChains(driver) 137 | action.send_keys(Keys.TAB).perform() 138 | else: 139 | # 尝试查找并点击验证码按钮,但不强制 140 | try: 141 | code_buttons = driver.find_elements(By.XPATH, "//button[contains(text(), '验证码') or contains(text(), '获取')]") 142 | if code_buttons: 143 | # 鼠标移动到按钮 144 | action = ActionChains(driver) 145 | action.move_to_element(code_buttons[0]).perform() 146 | except: 147 | pass 148 | 149 | except Exception as e: 150 | print(f"填写手机号时出错: {e}") 151 | 152 | # 如果上面的方法失败,可以尝试打印页面源代码帮助调试 153 | print("页面源代码:") 154 | print(driver.page_source) 155 | 156 | except Exception as e: 157 | print(f"浏览器操作出错: {e}") 158 | 159 | print(f"手机号 {phone_number} 脚本执行完毕") 160 | # 注意:不要在这里调用driver.quit(),保持浏览器打开 161 | 162 | def open_multiple_browsers(phone_numbers): 163 | """ 164 | 同时打开多个浏览器实例并填写不同的手机号 165 | 166 | 参数: 167 | phone_numbers (list): 要填写的手机号列表 168 | """ 169 | threads = [] 170 | 171 | # 为每个手机号创建一个线程 172 | for phone in phone_numbers: 173 | thread = threading.Thread(target=auto_fill_phone, args=(phone,)) 174 | thread.daemon = False # 设置为非守护线程 175 | threads.append(thread) 176 | 177 | # 启动所有线程 178 | for thread in threads: 179 | thread.start() 180 | # 每个浏览器启动间隔随机延迟,更像人类行为 181 | random_sleep(2.0, 3.0) 182 | 183 | # 等待所有线程完成 184 | for thread in threads: 185 | thread.join() 186 | 187 | print("所有浏览器实例已启动并填写完毕") 188 | 189 | def extract_phone_numbers(text): 190 | """ 191 | 从提供的文本中提取手机号 192 | 193 | 参数: 194 | text (str): 包含手机号的文本 195 | 196 | 返回: 197 | list: 提取到的手机号列表 198 | """ 199 | # 中国手机号正则表达式模式(匹配11位数字) 200 | pattern = r'1[3-9]\d{9}' 201 | 202 | # 找出所有匹配的手机号 203 | phone_numbers = re.findall(pattern, text) 204 | 205 | # 特别处理用户提供的特定格式(表格形式的数据) 206 | # 尝试按行分割 207 | lines = text.split('\n') 208 | for line in lines: 209 | # 尝试按制表符或多个空格分割每行 210 | parts = re.split(r'\t|\s{2,}', line.strip()) 211 | for part in parts: 212 | # 如果部分内容看起来像手机号,添加到结果中 213 | if re.match(r'^1[3-9]\d{9}$', part.strip()): 214 | phone_numbers.append(part.strip()) 215 | 216 | # 去除重复的手机号 217 | unique_numbers = list(set(phone_numbers)) 218 | 219 | return unique_numbers 220 | 221 | if __name__ == "__main__": 222 | print("手机号批量填写工具") 223 | print("请粘贴包含手机号的文本,程序将自动提取并打开浏览器填写:") 224 | print("(输入完成后按两次回车确认)") 225 | 226 | # 收集用户输入直到遇到空行 227 | lines = [] 228 | while True: 229 | line = input() 230 | if not line: # 如果是空行 231 | break 232 | lines.append(line) 233 | 234 | # 将所有行合并为一个文本 235 | input_text = "\n".join(lines) 236 | 237 | # 从文本中提取手机号 238 | phone_numbers = extract_phone_numbers(input_text) 239 | 240 | # 检查是否找到手机号 241 | if not phone_numbers: 242 | print("未在输入文本中找到有效的手机号!") 243 | exit(1) 244 | 245 | # 显示找到的手机号 246 | print(f"\n成功提取到 {len(phone_numbers)} 个手机号:") 247 | for i, phone in enumerate(phone_numbers): 248 | print(f"{i+1}. {phone}") 249 | 250 | # 询问用户是否继续 251 | confirm = input("\n是否使用这些手机号启动浏览器? (y/n): ") 252 | if confirm.lower() != 'y': 253 | print("已取消操作。") 254 | exit(0) 255 | 256 | # 直接运行,不再进行确认 257 | print(f"\n正在启动 {len(phone_numbers)} 个浏览器并填写手机号...") 258 | open_multiple_browsers(phone_numbers) 259 | 260 | # 重要:保持脚本运行,防止浏览器关闭 261 | print("\n所有操作已完成。浏览器将保持打开状态。") 262 | print("请按Ctrl+C手动终止此脚本(当您使用完浏览器后)...") 263 | 264 | # 无限循环保持脚本运行 265 | try: 266 | while True: 267 | time.sleep(1000) 268 | except KeyboardInterrupt: 269 | print("\n脚本已终止,感谢使用!") -------------------------------------------------------------------------------- /.history/auto_phone_fill_20250309071634.py: -------------------------------------------------------------------------------- 1 | import undetected_chromedriver as uc 2 | from selenium.webdriver.common.by import By 3 | from selenium.webdriver.support.ui import WebDriverWait 4 | from selenium.webdriver.support import expected_conditions as EC 5 | from selenium.webdriver.common.action_chains import ActionChains 6 | from selenium.webdriver.common.keys import Keys 7 | import time 8 | import threading 9 | import random 10 | import string 11 | import os 12 | import re 13 | 14 | # 全局变量存储浏览器驱动实例,防止被垃圾回收 15 | browser_drivers = [] 16 | 17 | def random_sleep(min_seconds=0.5, max_seconds=2.0): 18 | """随机睡眠一段时间,模拟人类行为""" 19 | time.sleep(random.uniform(min_seconds, max_seconds)) 20 | 21 | # 不再使用人类模拟输入方法 22 | # def human_like_typing(element, text): 23 | # """模拟人类输入,有随机间隔""" 24 | # for char in text: 25 | # element.send_keys(char) 26 | # # 随机短暂停顿,模拟人类打字速度 27 | # time.sleep(random.uniform(0.05, 0.25)) 28 | 29 | def auto_fill_phone(phone_number): 30 | """ 31 | 自动打开SiliconFlow登录页面并填写手机号 32 | 33 | 参数: 34 | phone_number (str): 要填写的手机号码 35 | """ 36 | global browser_drivers 37 | 38 | print(f"开始为手机号 {phone_number} 自动填写表单...") 39 | 40 | # 创建一个临时目录作为用户数据目录,每次使用不同的目录以隔离会话 41 | user_data_dir = f"chrome_user_data_{phone_number}" 42 | 43 | # 确保目录存在 44 | os.makedirs(user_data_dir, exist_ok=True) 45 | 46 | try: 47 | # 使用undetected_chromedriver而不是标准selenium 48 | options = uc.ChromeOptions() 49 | 50 | # 添加随机用户代理 51 | user_agents = [ 52 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36", 53 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.6943.143 Safari/537.36", 54 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0", 55 | "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15", 56 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.6943.143 Safari/537.36 Edg/120.0.0.0" 57 | ] 58 | options.add_argument(f"user-agent={random.choice(user_agents)}") 59 | 60 | # 设置用户数据目录 61 | options.add_argument(f"--user-data-dir={os.path.abspath(user_data_dir)}") 62 | 63 | # 设置首次运行参数,避免显示首次运行对话框 64 | options.add_argument("--no-first-run") 65 | options.add_argument("--no-default-browser-check") 66 | 67 | # 增加随机性,避免指纹追踪 68 | options.add_argument(f"--window-size={random.randint(1000, 1920)},{random.randint(700, 1080)}") 69 | 70 | # 增加会话隐私性 71 | options.add_argument("--incognito") 72 | 73 | # 禁用自动化扩展 74 | options.add_argument("--disable-blink-features=AutomationControlled") 75 | 76 | # 初始化undetected_chromedriver,强制使用与当前Chrome版本兼容的驱动 77 | driver = uc.Chrome( 78 | options=options, 79 | driver_executable_path=None, 80 | headless=False, 81 | version_main=133, # 固定使用Chrome 133版本的驱动 82 | use_subprocess=True, # 使用子进程运行,提高稳定性 83 | ) 84 | 85 | # 将驱动实例添加到全局列表中,防止被垃圾回收 86 | browser_drivers.append(driver) 87 | 88 | # 设置隐式等待 89 | driver.implicitly_wait(10) 90 | 91 | # 打开登录页面 92 | url = "https://account.siliconflow.cn/zh/login?redirect=https%3A%2F%2Fcloud.siliconflow.cn%2F%3F" 93 | driver.get(url) 94 | print(f"已为手机号 {phone_number} 打开登录页面") 95 | 96 | # 随机延迟,模拟人类阅读页面 97 | random_sleep(1.0, 2.0) 98 | 99 | # 尝试找到并填写手机号输入框 100 | try: 101 | # 尝试通过各种选择器找到输入框 102 | selectors = [ 103 | "//input[@placeholder='请输入手机号' or contains(@placeholder, '手机号')]", 104 | "//input[contains(@class, 'phone') or contains(@name, 'phone') or contains(@id, 'phone')]", 105 | "//input[@type='tel']" 106 | ] 107 | 108 | phone_input = None 109 | for selector in selectors: 110 | try: 111 | elements = driver.find_elements(By.XPATH, selector) 112 | if elements: 113 | phone_input = elements[0] 114 | break 115 | except: 116 | continue 117 | 118 | if not phone_input: 119 | print("未找到手机号输入框,尝试查看页面源码...") 120 | print(driver.page_source) 121 | return 122 | 123 | # 直接点击输入框 124 | phone_input.click() 125 | 126 | # 清空输入框 127 | phone_input.clear() 128 | 129 | # 直接输入手机号,不再模拟人类输入 130 | phone_input.send_keys(phone_number) 131 | 132 | print(f"已成功填写手机号: {phone_number}") 133 | 134 | # 可能的后续操作,如按下Tab键或点击获取验证码 135 | if random.choice([True, False]): 136 | action = ActionChains(driver) 137 | action.send_keys(Keys.TAB).perform() 138 | else: 139 | # 尝试查找并点击验证码按钮,但不强制 140 | try: 141 | code_buttons = driver.find_elements(By.XPATH, "//button[contains(text(), '验证码') or contains(text(), '获取')]") 142 | if code_buttons: 143 | # 鼠标移动到按钮 144 | action = ActionChains(driver) 145 | action.move_to_element(code_buttons[0]).perform() 146 | except: 147 | pass 148 | 149 | except Exception as e: 150 | print(f"填写手机号时出错: {e}") 151 | 152 | # 如果上面的方法失败,可以尝试打印页面源代码帮助调试 153 | print("页面源代码:") 154 | print(driver.page_source) 155 | 156 | except Exception as e: 157 | print(f"浏览器操作出错: {e}") 158 | 159 | print(f"手机号 {phone_number} 脚本执行完毕") 160 | # 注意:不要在这里调用driver.quit(),保持浏览器打开 161 | 162 | def open_multiple_browsers(phone_numbers): 163 | """ 164 | 同时打开多个浏览器实例并填写不同的手机号 165 | 166 | 参数: 167 | phone_numbers (list): 要填写的手机号列表 168 | """ 169 | threads = [] 170 | 171 | # 为每个手机号创建一个线程 172 | for phone in phone_numbers: 173 | thread = threading.Thread(target=auto_fill_phone, args=(phone,)) 174 | thread.daemon = False # 设置为非守护线程 175 | threads.append(thread) 176 | 177 | # 启动所有线程 178 | for thread in threads: 179 | thread.start() 180 | # 每个浏览器启动间隔随机延迟,更像人类行为 181 | random_sleep(2.0, 3.0) 182 | 183 | # 等待所有线程完成 184 | for thread in threads: 185 | thread.join() 186 | 187 | print("所有浏览器实例已启动并填写完毕") 188 | 189 | def extract_phone_numbers(text): 190 | """ 191 | 从提供的文本中提取手机号 192 | 193 | 参数: 194 | text (str): 包含手机号的文本 195 | 196 | 返回: 197 | list: 提取到的手机号列表 198 | """ 199 | # 中国手机号正则表达式模式(匹配11位数字) 200 | pattern = r'1[3-9]\d{9}' 201 | 202 | # 找出所有匹配的手机号 203 | phone_numbers = re.findall(pattern, text) 204 | 205 | # 特别处理用户提供的特定格式(表格形式的数据) 206 | # 尝试按行分割 207 | lines = text.split('\n') 208 | for line in lines: 209 | # 尝试按制表符或多个空格分割每行 210 | parts = re.split(r'\t|\s{2,}', line.strip()) 211 | for part in parts: 212 | # 如果部分内容看起来像手机号,添加到结果中 213 | if re.match(r'^1[3-9]\d{9}$', part.strip()): 214 | phone_numbers.append(part.strip()) 215 | 216 | # 去除重复的手机号 217 | unique_numbers = list(set(phone_numbers)) 218 | 219 | return unique_numbers 220 | 221 | if __name__ == "__main__": 222 | print("手机号批量填写工具") 223 | print("请粘贴包含手机号的文本,程序将自动提取并打开浏览器填写:") 224 | print("(输入完成后按两次回车确认)") 225 | 226 | # 收集用户输入直到遇到空行 227 | lines = [] 228 | while True: 229 | line = input() 230 | if not line: # 如果是空行 231 | break 232 | lines.append(line) 233 | 234 | # 将所有行合并为一个文本 235 | input_text = "\n".join(lines) 236 | 237 | # 从文本中提取手机号 238 | phone_numbers = extract_phone_numbers(input_text) 239 | 240 | # 检查是否找到手机号 241 | if not phone_numbers: 242 | print("未在输入文本中找到有效的手机号!") 243 | exit(1) 244 | 245 | # 显示找到的手机号 246 | print(f"\n成功提取到 {len(phone_numbers)} 个手机号:") 247 | for i, phone in enumerate(phone_numbers): 248 | print(f"{i+1}. {phone}") 249 | 250 | # 询问用户是否继续 251 | confirm = input("\n是否使用这些手机号启动浏览器? (y/n): ") 252 | if confirm.lower() != 'y': 253 | print("已取消操作。") 254 | exit(0) 255 | 256 | # 直接运行,不再进行确认 257 | print(f"\n正在启动 {len(phone_numbers)} 个浏览器并填写手机号...") 258 | open_multiple_browsers(phone_numbers) 259 | 260 | # 重要:保持脚本运行,防止浏览器关闭 261 | print("\n所有操作已完成。浏览器将保持打开状态。") 262 | print("请按Ctrl+C手动终止此脚本(当您使用完浏览器后)...") 263 | 264 | # 无限循环保持脚本运行 265 | try: 266 | while True: 267 | time.sleep(1000) 268 | except KeyboardInterrupt: 269 | print("\n脚本已终止,感谢使用!") -------------------------------------------------------------------------------- /.history/auto_phone_fill_20250309072659.py: -------------------------------------------------------------------------------- 1 | import undetected_chromedriver as uc 2 | from selenium.webdriver.common.by import By 3 | from selenium.webdriver.support.ui import WebDriverWait 4 | from selenium.webdriver.support import expected_conditions as EC 5 | from selenium.webdriver.common.action_chains import ActionChains 6 | from selenium.webdriver.common.keys import Keys 7 | import time 8 | import threading 9 | import random 10 | import string 11 | import os 12 | import re 13 | 14 | # 全局变量存储浏览器驱动实例,防止被垃圾回收 15 | browser_drivers = [] 16 | 17 | def random_sleep(min_seconds=0.5, max_seconds=2.0): 18 | """随机睡眠一段时间,模拟人类行为""" 19 | time.sleep(random.uniform(min_seconds, max_seconds)) 20 | 21 | # 不再使用人类模拟输入方法 22 | # def human_like_typing(element, text): 23 | # """模拟人类输入,有随机间隔""" 24 | # for char in text: 25 | # element.send_keys(char) 26 | # # 随机短暂停顿,模拟人类打字速度 27 | # time.sleep(random.uniform(0.05, 0.25)) 28 | 29 | def auto_fill_phone(phone_number): 30 | """ 31 | 自动打开SiliconFlow登录页面并填写手机号 32 | 33 | 参数: 34 | phone_number (str): 要填写的手机号码 35 | """ 36 | global browser_drivers 37 | 38 | print(f"开始为手机号 {phone_number} 自动填写表单...") 39 | 40 | # 创建一个临时目录作为用户数据目录,每次使用不同的目录以隔离会话 41 | user_data_dir = f"chrome_user_data_{phone_number}" 42 | 43 | # 确保目录存在 44 | os.makedirs(user_data_dir, exist_ok=True) 45 | 46 | try: 47 | # 使用undetected_chromedriver而不是标准selenium 48 | options = uc.ChromeOptions() 49 | 50 | # 添加随机用户代理 51 | user_agents = [ 52 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36", 53 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.6943.143 Safari/537.36", 54 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0", 55 | "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15", 56 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.6943.143 Safari/537.36 Edg/120.0.0.0" 57 | ] 58 | options.add_argument(f"user-agent={random.choice(user_agents)}") 59 | 60 | # 设置用户数据目录 61 | options.add_argument(f"--user-data-dir={os.path.abspath(user_data_dir)}") 62 | 63 | # 设置首次运行参数,避免显示首次运行对话框 64 | options.add_argument("--no-first-run") 65 | options.add_argument("--no-default-browser-check") 66 | 67 | # 增加随机性,避免指纹追踪 68 | options.add_argument(f"--window-size={random.randint(1000, 1920)},{random.randint(700, 1080)}") 69 | 70 | # 增加会话隐私性 71 | options.add_argument("--incognito") 72 | 73 | # 禁用自动化扩展 74 | options.add_argument("--disable-blink-features=AutomationControlled") 75 | 76 | # 初始化undetected_chromedriver,强制使用与当前Chrome版本兼容的驱动 77 | driver = uc.Chrome( 78 | options=options, 79 | driver_executable_path=None, 80 | headless=False, 81 | version_main=133, # 固定使用Chrome 133版本的驱动 82 | use_subprocess=True, # 使用子进程运行,提高稳定性 83 | ) 84 | 85 | # 将驱动实例添加到全局列表中,防止被垃圾回收 86 | browser_drivers.append(driver) 87 | 88 | # 设置隐式等待 89 | driver.implicitly_wait(10) 90 | 91 | # 打开登录页面 92 | url = "https://account.siliconflow.cn/zh/login?redirect=https%3A%2F%2Fcloud.siliconflow.cn%2F%3F" 93 | driver.get(url) 94 | print(f"已为手机号 {phone_number} 打开登录页面") 95 | 96 | # 随机延迟,模拟人类阅读页面 97 | random_sleep(1.0, 2.0) 98 | 99 | # 尝试找到并填写手机号输入框 100 | try: 101 | # 尝试通过各种选择器找到输入框 102 | selectors = [ 103 | "//input[@placeholder='请输入手机号' or contains(@placeholder, '手机号')]", 104 | "//input[contains(@class, 'phone') or contains(@name, 'phone') or contains(@id, 'phone')]", 105 | "//input[@type='tel']" 106 | ] 107 | 108 | phone_input = None 109 | for selector in selectors: 110 | try: 111 | elements = driver.find_elements(By.XPATH, selector) 112 | if elements: 113 | phone_input = elements[0] 114 | break 115 | except: 116 | continue 117 | 118 | if not phone_input: 119 | print("未找到手机号输入框,尝试查看页面源码...") 120 | print(driver.page_source) 121 | return 122 | 123 | # 直接点击输入框 124 | phone_input.click() 125 | 126 | # 清空输入框 127 | phone_input.clear() 128 | 129 | # 直接输入手机号,不再模拟人类输入 130 | phone_input.send_keys(phone_number) 131 | 132 | print(f"已成功填写手机号: {phone_number}") 133 | 134 | # 可能的后续操作,如按下Tab键或点击获取验证码 135 | if random.choice([True, False]): 136 | action = ActionChains(driver) 137 | action.send_keys(Keys.TAB).perform() 138 | else: 139 | # 尝试查找并点击验证码按钮,但不强制 140 | try: 141 | code_buttons = driver.find_elements(By.XPATH, "//button[contains(text(), '验证码') or contains(text(), '获取')]") 142 | if code_buttons: 143 | # 鼠标移动到按钮 144 | action = ActionChains(driver) 145 | action.move_to_element(code_buttons[0]).perform() 146 | except: 147 | pass 148 | 149 | except Exception as e: 150 | print(f"填写手机号时出错: {e}") 151 | 152 | # 如果上面的方法失败,可以尝试打印页面源代码帮助调试 153 | print("页面源代码:") 154 | print(driver.page_source) 155 | 156 | except Exception as e: 157 | print(f"浏览器操作出错: {e}") 158 | 159 | print(f"手机号 {phone_number} 脚本执行完毕") 160 | # 注意:不要在这里调用driver.quit(),保持浏览器打开 161 | 162 | def open_multiple_browsers(phone_numbers): 163 | """ 164 | 同时打开多个浏览器实例并填写不同的手机号 165 | 166 | 参数: 167 | phone_numbers (list): 要填写的手机号列表 168 | """ 169 | threads = [] 170 | 171 | # 为每个手机号创建一个线程 172 | for phone in phone_numbers: 173 | thread = threading.Thread(target=auto_fill_phone, args=(phone,)) 174 | thread.daemon = False # 设置为非守护线程 175 | threads.append(thread) 176 | 177 | # 启动所有线程 178 | for thread in threads: 179 | thread.start() 180 | # 每个浏览器启动间隔随机延迟,更像人类行为 181 | random_sleep(2.0, 3.0) 182 | 183 | # 等待所有线程完成 184 | for thread in threads: 185 | thread.join() 186 | 187 | print("所有浏览器实例已启动并填写完毕") 188 | 189 | def extract_phone_numbers(text): 190 | """ 191 | 从提供的文本中提取手机号 - 使用逐字符扫描的方式提取所有可能的11位手机号 192 | 193 | 参数: 194 | text (str): 包含手机号的文本 195 | 196 | 返回: 197 | list: 提取到的手机号列表 198 | """ 199 | print("\n开始扫描文本中的手机号...") 200 | 201 | # 首先移除文本中所有的空白字符(空格、制表符、换行符等) 202 | # 这样就不会因为空格或格式问题而导致手机号识别失败 203 | clean_text = ''.join(text.split()) 204 | print(f"清理后的文本长度: {len(clean_text)} 字符") 205 | 206 | # 存储找到的手机号 207 | found_phones = [] 208 | 209 | # 逐字符扫描文本 210 | i = 0 211 | while i <= len(clean_text) - 11: # 需要至少11个字符才能形成手机号 212 | # 检查当前位置开始的11个字符是否是手机号 213 | potential_phone = clean_text[i:i+11] 214 | 215 | # 检查是否符合中国大陆手机号的格式(1开头的11位数字) 216 | if potential_phone[0] == '1' and potential_phone.isdigit(): 217 | # 进一步验证第二位是否在3-9之间 218 | if '3' <= potential_phone[1] <= '9': 219 | found_phones.append(potential_phone) 220 | print(f"在位置 {i} 找到手机号: {potential_phone}") 221 | 222 | # 跳过这个手机号的剩余部分 223 | i += 11 224 | continue 225 | 226 | # 移动到下一个字符 227 | i += 1 228 | 229 | # 去除重复的手机号 230 | unique_phones = list(set(found_phones)) 231 | 232 | # 最终结果 233 | print(f"\n通过扫描找到 {len(unique_phones)} 个唯一手机号: {unique_phones}") 234 | 235 | # 备用方法:如果扫描方法没有找到任何手机号,尝试直接使用正则表达式 236 | if not unique_phones: 237 | print("扫描方法未找到手机号,尝试使用正则表达式...") 238 | # 直接使用正则表达式查找所有1开头的11位数字 239 | regex_phones = re.findall(r'1[3-9]\d{9}', text) 240 | if regex_phones: 241 | unique_phones = list(set(regex_phones)) 242 | print(f"通过正则表达式找到 {len(unique_phones)} 个手机号: {unique_phones}") 243 | 244 | return unique_phones 245 | 246 | if __name__ == "__main__": 247 | print("手机号批量填写工具") 248 | print("请粘贴包含手机号的文本,程序将自动提取并打开浏览器填写:") 249 | print("(输入完成后按两次回车确认)") 250 | 251 | # 收集用户输入直到遇到空行 252 | lines = [] 253 | while True: 254 | line = input() 255 | if not line: # 如果是空行 256 | break 257 | lines.append(line) 258 | 259 | # 将所有行合并为一个文本 260 | input_text = "\n".join(lines) 261 | 262 | # 从文本中提取手机号 263 | phone_numbers = extract_phone_numbers(input_text) 264 | 265 | # 检查是否找到手机号 266 | if not phone_numbers: 267 | print("未在输入文本中找到有效的手机号!") 268 | exit(1) 269 | 270 | # 显示找到的手机号 271 | print(f"\n成功提取到 {len(phone_numbers)} 个手机号:") 272 | for i, phone in enumerate(phone_numbers): 273 | print(f"{i+1}. {phone}") 274 | 275 | # 询问用户是否继续 276 | confirm = input("\n是否使用这些手机号启动浏览器? (y/n): ") 277 | if confirm.lower() != 'y': 278 | print("已取消操作。") 279 | exit(0) 280 | 281 | # 直接运行,不再进行确认 282 | print(f"\n正在启动 {len(phone_numbers)} 个浏览器并填写手机号...") 283 | open_multiple_browsers(phone_numbers) 284 | 285 | # 重要:保持脚本运行,防止浏览器关闭 286 | print("\n所有操作已完成。浏览器将保持打开状态。") 287 | print("请按Ctrl+C手动终止此脚本(当您使用完浏览器后)...") 288 | 289 | # 无限循环保持脚本运行 290 | try: 291 | while True: 292 | time.sleep(1000) 293 | except KeyboardInterrupt: 294 | print("\n脚本已终止,感谢使用!") -------------------------------------------------------------------------------- /.history/auto_phone_fill_20250309081108.py: -------------------------------------------------------------------------------- 1 | import undetected_chromedriver as uc 2 | from selenium.webdriver.common.by import By 3 | from selenium.webdriver.support.ui import WebDriverWait 4 | from selenium.webdriver.support import expected_conditions as EC 5 | from selenium.webdriver.common.action_chains import ActionChains 6 | from selenium.webdriver.common.keys import Keys 7 | import time 8 | import threading 9 | import random 10 | import string 11 | import os 12 | import re 13 | 14 | # 全局变量存储浏览器驱动实例,防止被垃圾回收 15 | browser_drivers = [] 16 | 17 | def random_sleep(min_seconds=0.5, max_seconds=2.0): 18 | """随机睡眠一段时间,模拟人类行为""" 19 | time.sleep(random.uniform(min_seconds, max_seconds)) 20 | 21 | # 不再使用人类模拟输入方法 22 | # def human_like_typing(element, text): 23 | # """模拟人类输入,有随机间隔""" 24 | # for char in text: 25 | # element.send_keys(char) 26 | # # 随机短暂停顿,模拟人类打字速度 27 | # time.sleep(random.uniform(0.05, 0.25)) 28 | 29 | def clean_text(text): 30 | """ 31 | 彻底清理文本,去除所有空格、换行等空白字符 32 | 33 | 参数: 34 | text (str): 原始文本 35 | 36 | 返回: 37 | str: 清理后的纯文本(只包含非空白字符) 38 | """ 39 | # 移除所有空白字符(空格、制表符、换行符等) 40 | return ''.join(text.split()) 41 | 42 | def auto_fill_phone(phone_number): 43 | """ 44 | 自动打开SiliconFlow登录页面并填写手机号 45 | 46 | 参数: 47 | phone_number (str): 要填写的手机号码 48 | """ 49 | global browser_drivers 50 | 51 | print(f"开始为手机号 {phone_number} 自动填写表单...") 52 | 53 | # 创建一个临时目录作为用户数据目录,每次使用不同的目录以隔离会话 54 | user_data_dir = f"chrome_user_data_{phone_number}" 55 | 56 | # 确保目录存在 57 | os.makedirs(user_data_dir, exist_ok=True) 58 | 59 | try: 60 | # 使用undetected_chromedriver而不是标准selenium 61 | options = uc.ChromeOptions() 62 | 63 | # 添加随机用户代理 64 | user_agents = [ 65 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36", 66 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.6943.143 Safari/537.36", 67 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0", 68 | "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15", 69 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.6943.143 Safari/537.36 Edg/120.0.0.0" 70 | ] 71 | options.add_argument(f"user-agent={random.choice(user_agents)}") 72 | 73 | # 设置用户数据目录 74 | options.add_argument(f"--user-data-dir={os.path.abspath(user_data_dir)}") 75 | 76 | # 设置首次运行参数,避免显示首次运行对话框 77 | options.add_argument("--no-first-run") 78 | options.add_argument("--no-default-browser-check") 79 | 80 | # 增加随机性,避免指纹追踪 81 | options.add_argument(f"--window-size={random.randint(1000, 1920)},{random.randint(700, 1080)}") 82 | 83 | # 增加会话隐私性 84 | options.add_argument("--incognito") 85 | 86 | # 禁用自动化扩展 87 | options.add_argument("--disable-blink-features=AutomationControlled") 88 | 89 | # 初始化undetected_chromedriver,强制使用与当前Chrome版本兼容的驱动 90 | driver = uc.Chrome( 91 | options=options, 92 | driver_executable_path=None, 93 | headless=False, 94 | version_main=133, # 固定使用Chrome 133版本的驱动 95 | use_subprocess=True, # 使用子进程运行,提高稳定性 96 | ) 97 | 98 | # 将驱动实例添加到全局列表中,防止被垃圾回收 99 | browser_drivers.append(driver) 100 | 101 | # 设置隐式等待 102 | driver.implicitly_wait(10) 103 | 104 | # 打开登录页面 105 | url = "https://account.siliconflow.cn/zh/login?redirect=https%3A%2F%2Fcloud.siliconflow.cn%2F%3F" 106 | driver.get(url) 107 | print(f"已为手机号 {phone_number} 打开登录页面") 108 | 109 | # 随机延迟,模拟人类阅读页面 110 | random_sleep(1.0, 2.0) 111 | 112 | # 尝试找到并填写手机号输入框 113 | try: 114 | # 尝试通过各种选择器找到输入框 115 | selectors = [ 116 | "//input[@placeholder='请输入手机号' or contains(@placeholder, '手机号')]", 117 | "//input[contains(@class, 'phone') or contains(@name, 'phone') or contains(@id, 'phone')]", 118 | "//input[@type='tel']" 119 | ] 120 | 121 | phone_input = None 122 | for selector in selectors: 123 | try: 124 | elements = driver.find_elements(By.XPATH, selector) 125 | if elements: 126 | phone_input = elements[0] 127 | break 128 | except: 129 | continue 130 | 131 | if not phone_input: 132 | print("未找到手机号输入框,尝试查看页面源码...") 133 | print(driver.page_source) 134 | return 135 | 136 | # 直接点击输入框 137 | phone_input.click() 138 | 139 | # 清空输入框 140 | phone_input.clear() 141 | 142 | # 直接输入手机号,不再模拟人类输入 143 | phone_input.send_keys(phone_number) 144 | 145 | print(f"已成功填写手机号: {phone_number}") 146 | 147 | # 可能的后续操作,如按下Tab键或点击获取验证码 148 | if random.choice([True, False]): 149 | action = ActionChains(driver) 150 | action.send_keys(Keys.TAB).perform() 151 | else: 152 | # 尝试查找并点击验证码按钮,但不强制 153 | try: 154 | code_buttons = driver.find_elements(By.XPATH, "//button[contains(text(), '验证码') or contains(text(), '获取')]") 155 | if code_buttons: 156 | # 鼠标移动到按钮 157 | action = ActionChains(driver) 158 | action.move_to_element(code_buttons[0]).perform() 159 | except: 160 | pass 161 | 162 | except Exception as e: 163 | print(f"填写手机号时出错: {e}") 164 | 165 | # 如果上面的方法失败,可以尝试打印页面源代码帮助调试 166 | print("页面源代码:") 167 | print(driver.page_source) 168 | 169 | except Exception as e: 170 | print(f"浏览器操作出错: {e}") 171 | 172 | print(f"手机号 {phone_number} 脚本执行完毕") 173 | # 注意:不要在这里调用driver.quit(),保持浏览器打开 174 | 175 | def open_multiple_browsers(phone_numbers): 176 | """ 177 | 同时打开多个浏览器实例并填写不同的手机号 178 | 179 | 参数: 180 | phone_numbers (list): 要填写的手机号列表 181 | """ 182 | threads = [] 183 | 184 | # 为每个手机号创建一个线程 185 | for phone in phone_numbers: 186 | thread = threading.Thread(target=auto_fill_phone, args=(phone,)) 187 | thread.daemon = False # 设置为非守护线程 188 | threads.append(thread) 189 | 190 | # 启动所有线程 191 | for thread in threads: 192 | thread.start() 193 | # 每个浏览器启动间隔随机延迟,更像人类行为 194 | random_sleep(2.0, 3.0) 195 | 196 | # 等待所有线程完成 197 | for thread in threads: 198 | thread.join() 199 | 200 | print("所有浏览器实例已启动并填写完毕") 201 | 202 | def extract_phone_numbers_from_clean_text(text): 203 | """ 204 | 从完全清理后的文本中提取手机号(逐字符扫描方法) 205 | 206 | 参数: 207 | text (str): 已清理的文本(无空白字符) 208 | 209 | 返回: 210 | list: 提取到的手机号列表 211 | """ 212 | # 存储找到的手机号 213 | found_phones = [] 214 | 215 | # 逐字符扫描文本 216 | i = 0 217 | while i <= len(text) - 11: # 需要至少11个字符才能形成手机号 218 | # 检查当前位置开始的11个字符是否是手机号 219 | potential_phone = text[i:i+11] 220 | 221 | # 检查是否符合中国大陆手机号的格式(1开头的11位数字) 222 | if potential_phone[0] == '1' and potential_phone.isdigit(): 223 | # 进一步验证第二位是否在3-9之间 224 | if '3' <= potential_phone[1] <= '9': 225 | found_phones.append(potential_phone) 226 | print(f"在位置 {i} 找到手机号: {potential_phone}") 227 | 228 | # 跳过这个手机号的剩余部分 229 | i += 11 230 | continue 231 | 232 | # 移动到下一个字符 233 | i += 1 234 | 235 | # 去除重复的手机号 236 | unique_phones = list(set(found_phones)) 237 | return unique_phones 238 | 239 | if __name__ == "__main__": 240 | print("手机号批量填写工具") 241 | print("请粘贴包含手机号的文本,将会自动移除所有空格和换行,直接提取手机号") 242 | print("(输入完成后按两次回车确认)") 243 | 244 | # 收集用户输入直到遇到空行 245 | lines = [] 246 | while True: 247 | line = input() 248 | if not line: # 如果是空行 249 | break 250 | lines.append(line) 251 | 252 | # 将所有行合并为一个文本 253 | input_text = "\n".join(lines) 254 | 255 | # 彻底清理文本(去除所有空格和换行) 256 | cleaned_text = clean_text(input_text) 257 | print(f"\n清理后的文本长度: {len(cleaned_text)} 字符") 258 | 259 | # 从清理后的文本中提取手机号 260 | phone_numbers = extract_phone_numbers_from_clean_text(cleaned_text) 261 | 262 | # 检查是否找到手机号 263 | if not phone_numbers: 264 | print("未在输入文本中找到有效的手机号!") 265 | exit(1) 266 | 267 | # 显示找到的手机号 268 | print(f"\n成功提取到 {len(phone_numbers)} 个手机号:") 269 | for i, phone in enumerate(phone_numbers): 270 | print(f"{i+1}. {phone}") 271 | 272 | # 询问用户是否继续 273 | confirm = input("\n是否使用这些手机号启动浏览器? (y/n): ") 274 | if confirm.lower() != 'y': 275 | print("已取消操作。") 276 | exit(0) 277 | 278 | # 直接运行,不再进行确认 279 | print(f"\n正在启动 {len(phone_numbers)} 个浏览器并填写手机号...") 280 | open_multiple_browsers(phone_numbers) 281 | 282 | # 重要:保持脚本运行,防止浏览器关闭 283 | print("\n所有操作已完成。浏览器将保持打开状态。") 284 | print("请按Ctrl+C手动终止此脚本(当您使用完浏览器后)...") 285 | 286 | # 无限循环保持脚本运行 287 | try: 288 | while True: 289 | time.sleep(1000) 290 | except KeyboardInterrupt: 291 | print("\n脚本已终止,感谢使用!") -------------------------------------------------------------------------------- /.history/auto_phone_fill_20250309081132.py: -------------------------------------------------------------------------------- 1 | import undetected_chromedriver as uc 2 | from selenium.webdriver.common.by import By 3 | from selenium.webdriver.support.ui import WebDriverWait 4 | from selenium.webdriver.support import expected_conditions as EC 5 | from selenium.webdriver.common.action_chains import ActionChains 6 | from selenium.webdriver.common.keys import Keys 7 | import time 8 | import threading 9 | import random 10 | import string 11 | import os 12 | import re 13 | 14 | # 全局变量存储浏览器驱动实例,防止被垃圾回收 15 | browser_drivers = [] 16 | 17 | def random_sleep(min_seconds=0.5, max_seconds=2.0): 18 | """随机睡眠一段时间,模拟人类行为""" 19 | time.sleep(random.uniform(min_seconds, max_seconds)) 20 | 21 | # 不再使用人类模拟输入方法 22 | # def human_like_typing(element, text): 23 | # """模拟人类输入,有随机间隔""" 24 | # for char in text: 25 | # element.send_keys(char) 26 | # # 随机短暂停顿,模拟人类打字速度 27 | # time.sleep(random.uniform(0.05, 0.25)) 28 | 29 | def clean_text(text): 30 | """ 31 | 彻底清理文本,去除所有空格、换行等空白字符 32 | 33 | 参数: 34 | text (str): 原始文本 35 | 36 | 返回: 37 | str: 清理后的纯文本(只包含非空白字符) 38 | """ 39 | # 移除所有空白字符(空格、制表符、换行符等) 40 | return ''.join(text.split()) 41 | 42 | def auto_fill_phone(phone_number): 43 | """ 44 | 自动打开SiliconFlow登录页面并填写手机号 45 | 46 | 参数: 47 | phone_number (str): 要填写的手机号码 48 | """ 49 | global browser_drivers 50 | 51 | print(f"开始为手机号 {phone_number} 自动填写表单...") 52 | 53 | # 创建一个临时目录作为用户数据目录,每次使用不同的目录以隔离会话 54 | user_data_dir = f"chrome_user_data_{phone_number}" 55 | 56 | # 确保目录存在 57 | os.makedirs(user_data_dir, exist_ok=True) 58 | 59 | try: 60 | # 使用undetected_chromedriver而不是标准selenium 61 | options = uc.ChromeOptions() 62 | 63 | # 添加随机用户代理 64 | user_agents = [ 65 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36", 66 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.6943.143 Safari/537.36", 67 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0", 68 | "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15", 69 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.6943.143 Safari/537.36 Edg/120.0.0.0" 70 | ] 71 | options.add_argument(f"user-agent={random.choice(user_agents)}") 72 | 73 | # 设置用户数据目录 74 | options.add_argument(f"--user-data-dir={os.path.abspath(user_data_dir)}") 75 | 76 | # 设置首次运行参数,避免显示首次运行对话框 77 | options.add_argument("--no-first-run") 78 | options.add_argument("--no-default-browser-check") 79 | 80 | # 增加随机性,避免指纹追踪 81 | options.add_argument(f"--window-size={random.randint(1000, 1920)},{random.randint(700, 1080)}") 82 | 83 | # 增加会话隐私性 84 | options.add_argument("--incognito") 85 | 86 | # 禁用自动化扩展 87 | options.add_argument("--disable-blink-features=AutomationControlled") 88 | 89 | # 初始化undetected_chromedriver,强制使用与当前Chrome版本兼容的驱动 90 | driver = uc.Chrome( 91 | options=options, 92 | driver_executable_path=None, 93 | headless=False, 94 | version_main=133, # 固定使用Chrome 133版本的驱动 95 | use_subprocess=True, # 使用子进程运行,提高稳定性 96 | ) 97 | 98 | # 将驱动实例添加到全局列表中,防止被垃圾回收 99 | browser_drivers.append(driver) 100 | 101 | # 设置隐式等待 102 | driver.implicitly_wait(10) 103 | 104 | # 打开登录页面 105 | url = "https://account.siliconflow.cn/zh/login?redirect=https%3A%2F%2Fcloud.siliconflow.cn%2F%3F" 106 | driver.get(url) 107 | print(f"已为手机号 {phone_number} 打开登录页面") 108 | 109 | # 随机延迟,模拟人类阅读页面 110 | random_sleep(1.0, 2.0) 111 | 112 | # 尝试找到并填写手机号输入框 113 | try: 114 | # 尝试通过各种选择器找到输入框 115 | selectors = [ 116 | "//input[@placeholder='请输入手机号' or contains(@placeholder, '手机号')]", 117 | "//input[contains(@class, 'phone') or contains(@name, 'phone') or contains(@id, 'phone')]", 118 | "//input[@type='tel']" 119 | ] 120 | 121 | phone_input = None 122 | for selector in selectors: 123 | try: 124 | elements = driver.find_elements(By.XPATH, selector) 125 | if elements: 126 | phone_input = elements[0] 127 | break 128 | except: 129 | continue 130 | 131 | if not phone_input: 132 | print("未找到手机号输入框,尝试查看页面源码...") 133 | print(driver.page_source) 134 | return 135 | 136 | # 直接点击输入框 137 | phone_input.click() 138 | 139 | # 清空输入框 140 | phone_input.clear() 141 | 142 | # 直接输入手机号,不再模拟人类输入 143 | phone_input.send_keys(phone_number) 144 | 145 | print(f"已成功填写手机号: {phone_number}") 146 | 147 | # 可能的后续操作,如按下Tab键或点击获取验证码 148 | if random.choice([True, False]): 149 | action = ActionChains(driver) 150 | action.send_keys(Keys.TAB).perform() 151 | else: 152 | # 尝试查找并点击验证码按钮,但不强制 153 | try: 154 | code_buttons = driver.find_elements(By.XPATH, "//button[contains(text(), '验证码') or contains(text(), '获取')]") 155 | if code_buttons: 156 | # 鼠标移动到按钮 157 | action = ActionChains(driver) 158 | action.move_to_element(code_buttons[0]).perform() 159 | except: 160 | pass 161 | 162 | except Exception as e: 163 | print(f"填写手机号时出错: {e}") 164 | 165 | # 如果上面的方法失败,可以尝试打印页面源代码帮助调试 166 | print("页面源代码:") 167 | print(driver.page_source) 168 | 169 | except Exception as e: 170 | print(f"浏览器操作出错: {e}") 171 | 172 | print(f"手机号 {phone_number} 脚本执行完毕") 173 | # 注意:不要在这里调用driver.quit(),保持浏览器打开 174 | 175 | def open_multiple_browsers(phone_numbers): 176 | """ 177 | 同时打开多个浏览器实例并填写不同的手机号 178 | 179 | 参数: 180 | phone_numbers (list): 要填写的手机号列表 181 | """ 182 | threads = [] 183 | 184 | # 为每个手机号创建一个线程 185 | for phone in phone_numbers: 186 | thread = threading.Thread(target=auto_fill_phone, args=(phone,)) 187 | thread.daemon = False # 设置为非守护线程 188 | threads.append(thread) 189 | 190 | # 启动所有线程 191 | for thread in threads: 192 | thread.start() 193 | # 每个浏览器启动间隔随机延迟,更像人类行为 194 | random_sleep(2.0, 3.0) 195 | 196 | # 等待所有线程完成 197 | for thread in threads: 198 | thread.join() 199 | 200 | print("所有浏览器实例已启动并填写完毕") 201 | 202 | def extract_phone_numbers_from_clean_text(text): 203 | """ 204 | 从完全清理后的文本中提取手机号(逐字符扫描方法) 205 | 206 | 参数: 207 | text (str): 已清理的文本(无空白字符) 208 | 209 | 返回: 210 | list: 提取到的手机号列表 211 | """ 212 | # 存储找到的手机号 213 | found_phones = [] 214 | 215 | # 逐字符扫描文本 216 | i = 0 217 | while i <= len(text) - 11: # 需要至少11个字符才能形成手机号 218 | # 检查当前位置开始的11个字符是否是手机号 219 | potential_phone = text[i:i+11] 220 | 221 | # 检查是否符合中国大陆手机号的格式(1开头的11位数字) 222 | if potential_phone[0] == '1' and potential_phone.isdigit(): 223 | # 进一步验证第二位是否在3-9之间 224 | if '3' <= potential_phone[1] <= '9': 225 | found_phones.append(potential_phone) 226 | print(f"在位置 {i} 找到手机号: {potential_phone}") 227 | 228 | # 跳过这个手机号的剩余部分 229 | i += 11 230 | continue 231 | 232 | # 移动到下一个字符 233 | i += 1 234 | 235 | # 去除重复的手机号 236 | unique_phones = list(set(found_phones)) 237 | return unique_phones 238 | 239 | if __name__ == "__main__": 240 | print("手机号批量填写工具") 241 | print("请粘贴包含手机号的文本,将会自动移除所有空格和换行,直接提取手机号") 242 | print("(输入完成后按两次回车确认)") 243 | 244 | # 收集用户输入直到遇到空行 245 | lines = [] 246 | while True: 247 | line = input() 248 | if not line: # 如果是空行 249 | break 250 | lines.append(line) 251 | 252 | # 将所有行合并为一个文本 253 | input_text = "\n".join(lines) 254 | 255 | # 彻底清理文本(去除所有空格和换行) 256 | cleaned_text = clean_text(input_text) 257 | print(f"\n清理后的文本长度: {len(cleaned_text)} 字符") 258 | 259 | # 从清理后的文本中提取手机号 260 | phone_numbers = extract_phone_numbers_from_clean_text(cleaned_text) 261 | 262 | # 检查是否找到手机号 263 | if not phone_numbers: 264 | print("未在输入文本中找到有效的手机号!") 265 | exit(1) 266 | 267 | # 显示找到的手机号 268 | print(f"\n成功提取到 {len(phone_numbers)} 个手机号:") 269 | for i, phone in enumerate(phone_numbers): 270 | print(f"{i+1}. {phone}") 271 | 272 | # 询问用户是否继续 273 | confirm = input("\n是否使用这些手机号启动浏览器? (y/n): ") 274 | if confirm.lower() != 'y': 275 | print("已取消操作。") 276 | exit(0) 277 | 278 | # 直接运行,不再进行确认 279 | print(f"\n正在启动 {len(phone_numbers)} 个浏览器并填写手机号...") 280 | open_multiple_browsers(phone_numbers) 281 | 282 | # 重要:保持脚本运行,防止浏览器关闭 283 | print("\n所有操作已完成。浏览器将保持打开状态。") 284 | print("请按Ctrl+C手动终止此脚本(当您使用完浏览器后)...") 285 | 286 | # 无限循环保持脚本运行 287 | try: 288 | while True: 289 | time.sleep(1000) 290 | except KeyboardInterrupt: 291 | print("\n脚本已终止,感谢使用!") -------------------------------------------------------------------------------- /.history/browser_launcher_20250309085101.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.history/click_api_key_20250309104713.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.history/click_api_key_20250309104922.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.history/data_cleaner_20250309081405.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.history/data_cleaner_20250309081408.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | 数据清理脚本 6 | 功能:去除文本中的所有空格、制表符、换行符等空白字符 7 | """ 8 | 9 | import os 10 | import re 11 | 12 | def clean_text(text): 13 | """ 14 | 去除文本中的所有空白字符(空格、制表符、换行符等) 15 | 16 | 参数: 17 | text (str): 原始文本 18 | 19 | 返回: 20 | str: 清理后的纯文本(不包含任何空白字符) 21 | """ 22 | return ''.join(text.split()) 23 | 24 | def clean_from_input(): 25 | """从用户输入获取文本并清理""" 26 | print("请输入或粘贴要处理的文本(输入完成后按两次回车结束):") 27 | 28 | lines = [] 29 | while True: 30 | line = input() 31 | if not line: # 如果是空行,结束输入 32 | break 33 | lines.append(line) 34 | 35 | # 合并所有输入行 36 | input_text = "\n".join(lines) 37 | 38 | # 显示原始文本信息 39 | print(f"\n原始文本长度: {len(input_text)} 字符") 40 | print(f"原始文本行数: {len(lines)} 行") 41 | 42 | # 清理文本 43 | cleaned_text = clean_text(input_text) 44 | 45 | # 显示清理后的文本信息 46 | print(f"\n清理后的文本长度: {len(cleaned_text)} 字符") 47 | print("所有空格、换行和空白字符已移除") 48 | 49 | # 询问用户是否要查看清理后的文本 50 | show_text = input("\n是否显示清理后的文本?(y/n): ") 51 | if show_text.lower() == 'y': 52 | print("\n清理后的文本:") 53 | print("="*50) 54 | print(cleaned_text) 55 | print("="*50) 56 | 57 | # 询问用户是否要保存到文件 58 | save_to_file = input("\n是否保存到文件?(y/n): ") 59 | if save_to_file.lower() == 'y': 60 | filename = input("请输入文件名(默认为 cleaned_data.txt): ") or "cleaned_data.txt" 61 | with open(filename, 'w', encoding='utf-8') as f: 62 | f.write(cleaned_text) 63 | print(f"文件已保存为: {os.path.abspath(filename)}") 64 | 65 | return cleaned_text 66 | 67 | def clean_from_file(input_file, output_file=None): 68 | """从文件读取文本并清理""" 69 | try: 70 | # 读取输入文件 71 | with open(input_file, 'r', encoding='utf-8') as f: 72 | input_text = f.read() 73 | 74 | # 显示原始文本信息 75 | print(f"\n原始文件: {input_file}") 76 | print(f"原始文本长度: {len(input_text)} 字符") 77 | 78 | # 清理文本 79 | cleaned_text = clean_text(input_text) 80 | 81 | # 显示清理后的文本信息 82 | print(f"\n清理后的文本长度: {len(cleaned_text)} 字符") 83 | print("所有空格、换行和空白字符已移除") 84 | 85 | # 如果指定了输出文件,保存清理后的文本 86 | if output_file: 87 | with open(output_file, 'w', encoding='utf-8') as f: 88 | f.write(cleaned_text) 89 | print(f"清理后的文本已保存到: {output_file}") 90 | 91 | return cleaned_text 92 | 93 | except Exception as e: 94 | print(f"处理文件时出错: {e}") 95 | return None 96 | 97 | def main(): 98 | """主函数""" 99 | print("文本数据清理工具 - 去除所有空格和换行") 100 | print("=" * 40) 101 | 102 | while True: 103 | print("\n请选择操作:") 104 | print("1. 输入或粘贴文本进行处理") 105 | print("2. 从文件读取文本进行处理") 106 | print("3. 退出") 107 | 108 | choice = input("请选择 [1/2/3]: ") 109 | 110 | if choice == '1': 111 | clean_from_input() 112 | elif choice == '2': 113 | input_file = input("请输入源文件路径: ") 114 | save_option = input("是否保存处理后的文本到文件? (y/n): ") 115 | 116 | if save_option.lower() == 'y': 117 | output_file = input("请输入目标文件路径(默认为 cleaned_data.txt): ") or "cleaned_data.txt" 118 | clean_from_file(input_file, output_file) 119 | else: 120 | clean_from_file(input_file) 121 | elif choice == '3': 122 | print("感谢使用,再见!") 123 | break 124 | else: 125 | print("无效的选择,请重试。") 126 | 127 | if __name__ == "__main__": 128 | main() -------------------------------------------------------------------------------- /.history/data_cleaner_20250309081809.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | 数据清理脚本 6 | 功能:去除文本中的所有空格、制表符、换行符等空白字符,并提取手机号 7 | """ 8 | 9 | import os 10 | import re 11 | 12 | def clean_text(text): 13 | """ 14 | 去除文本中的所有空白字符(空格、制表符、换行符等) 15 | 16 | 参数: 17 | text (str): 原始文本 18 | 19 | 返回: 20 | str: 清理后的纯文本(不包含任何空白字符) 21 | """ 22 | return ''.join(text.split()) 23 | 24 | def extract_phone_numbers(text): 25 | """ 26 | 从文本中提取中国大陆手机号 27 | 28 | 参数: 29 | text (str): 要提取手机号的文本 30 | 31 | 返回: 32 | list: 提取到的手机号列表 33 | """ 34 | phone_numbers = [] 35 | i = 0 36 | while i <= len(text) - 11: # 需要至少11个字符才能形成手机号 37 | # 检查当前位置开始的11个字符是否是手机号 38 | potential_phone = text[i:i+11] 39 | 40 | # 检查是否符合中国大陆手机号的格式(1开头的11位数字) 41 | if potential_phone[0] == '1' and potential_phone.isdigit(): 42 | # 进一步验证第二位是否在3-9之间 43 | if '3' <= potential_phone[1] <= '9': 44 | phone_numbers.append(potential_phone) 45 | # 跳过这个手机号的剩余部分 46 | i += 11 47 | continue 48 | 49 | # 移动到下一个字符 50 | i += 1 51 | 52 | # 去除重复的手机号 53 | return list(set(phone_numbers)) 54 | 55 | def clean_from_input(): 56 | """从用户输入获取文本并清理""" 57 | print("请输入或粘贴要处理的文本") 58 | print("输入完成后,请键入'END'然后按回车结束输入") 59 | print("这样可以确保处理所有数据,即使其中包含空行") 60 | 61 | lines = [] 62 | print("\n请开始输入文本(输入'END'结束):") 63 | while True: 64 | line = input() 65 | if line.strip() == "END": # 使用特定标记结束输入 66 | break 67 | lines.append(line) 68 | 69 | # 合并所有输入行 70 | input_text = "\n".join(lines) 71 | 72 | # 显示原始文本信息 73 | print(f"\n原始文本长度: {len(input_text)} 字符") 74 | print(f"原始文本行数: {len(lines)} 行") 75 | 76 | # 清理文本 77 | cleaned_text = clean_text(input_text) 78 | 79 | # 显示清理后的文本信息 80 | print(f"\n清理后的文本长度: {len(cleaned_text)} 字符") 81 | print("所有空格、换行和空白字符已移除") 82 | 83 | # 提取手机号 84 | phone_numbers = extract_phone_numbers(cleaned_text) 85 | 86 | # 显示提取到的手机号 87 | if phone_numbers: 88 | print("\n从清理后的文本中提取到的手机号:") 89 | for i, phone in enumerate(phone_numbers): 90 | print(f"{i+1}. {phone}") 91 | print(f"共找到 {len(phone_numbers)} 个手机号") 92 | else: 93 | print("\n未找到任何手机号") 94 | 95 | # 询问用户是否要查看清理后的文本 96 | show_text = input("\n是否显示清理后的文本?(y/n): ") 97 | if show_text.lower() == 'y': 98 | print("\n清理后的文本:") 99 | print("="*50) 100 | print(cleaned_text) 101 | print("="*50) 102 | 103 | # 询问用户是否要保存到文件 104 | save_to_file = input("\n是否保存到文件?(y/n): ") 105 | if save_to_file.lower() == 'y': 106 | filename = input("请输入文件名(默认为 cleaned_data.txt): ") or "cleaned_data.txt" 107 | with open(filename, 'w', encoding='utf-8') as f: 108 | f.write(cleaned_text) 109 | print(f"文件已保存为: {os.path.abspath(filename)}") 110 | 111 | # 询问是否保存提取到的手机号 112 | if phone_numbers: 113 | save_phones = input("是否保存提取到的手机号到文件? (y/n): ") 114 | if save_phones.lower() == 'y': 115 | phone_filename = input("请输入手机号文件名(默认为 phone_numbers.txt): ") or "phone_numbers.txt" 116 | with open(phone_filename, 'w', encoding='utf-8') as f: 117 | for phone in phone_numbers: 118 | f.write(phone + '\n') 119 | print(f"手机号已保存为: {os.path.abspath(phone_filename)}") 120 | 121 | return cleaned_text, phone_numbers 122 | 123 | def clean_from_file(input_file, output_file=None): 124 | """从文件读取文本并清理""" 125 | try: 126 | # 读取输入文件 127 | with open(input_file, 'r', encoding='utf-8') as f: 128 | input_text = f.read() 129 | 130 | # 显示原始文本信息 131 | print(f"\n原始文件: {input_file}") 132 | print(f"原始文本长度: {len(input_text)} 字符") 133 | 134 | # 清理文本 135 | cleaned_text = clean_text(input_text) 136 | 137 | # 显示清理后的文本信息 138 | print(f"\n清理后的文本长度: {len(cleaned_text)} 字符") 139 | print("所有空格、换行和空白字符已移除") 140 | 141 | # 提取手机号 142 | phone_numbers = extract_phone_numbers(cleaned_text) 143 | 144 | # 显示提取到的手机号 145 | if phone_numbers: 146 | print("\n从清理后的文本中提取到的手机号:") 147 | for i, phone in enumerate(phone_numbers): 148 | print(f"{i+1}. {phone}") 149 | print(f"共找到 {len(phone_numbers)} 个手机号") 150 | else: 151 | print("\n未找到任何手机号") 152 | 153 | # 如果指定了输出文件,保存清理后的文本 154 | if output_file: 155 | with open(output_file, 'w', encoding='utf-8') as f: 156 | f.write(cleaned_text) 157 | print(f"清理后的文本已保存到: {output_file}") 158 | 159 | # 如果找到了手机号,询问是否保存 160 | if phone_numbers: 161 | save_phones = input("是否保存提取到的手机号到文件? (y/n): ") 162 | if save_phones.lower() == 'y': 163 | phone_filename = input("请输入手机号文件名(默认为 phone_numbers.txt): ") or "phone_numbers.txt" 164 | with open(phone_filename, 'w', encoding='utf-8') as f: 165 | for phone in phone_numbers: 166 | f.write(phone + '\n') 167 | print(f"手机号已保存为: {os.path.abspath(phone_filename)}") 168 | 169 | return cleaned_text, phone_numbers 170 | 171 | except Exception as e: 172 | print(f"处理文件时出错: {e}") 173 | return None, None 174 | 175 | def main(): 176 | """主函数""" 177 | print("文本数据清理与手机号提取工具") 178 | print("=" * 40) 179 | 180 | while True: 181 | print("\n请选择操作:") 182 | print("1. 输入或粘贴文本进行处理") 183 | print("2. 从文件读取文本进行处理") 184 | print("3. 退出") 185 | 186 | choice = input("请选择 [1/2/3]: ") 187 | 188 | if choice == '1': 189 | clean_from_input() 190 | elif choice == '2': 191 | input_file = input("请输入源文件路径: ") 192 | save_option = input("是否保存处理后的文本到文件? (y/n): ") 193 | 194 | if save_option.lower() == 'y': 195 | output_file = input("请输入目标文件路径(默认为 cleaned_data.txt): ") or "cleaned_data.txt" 196 | clean_from_file(input_file, output_file) 197 | else: 198 | clean_from_file(input_file) 199 | elif choice == '3': 200 | print("感谢使用,再见!") 201 | break 202 | else: 203 | print("无效的选择,请重试。") 204 | 205 | if __name__ == "__main__": 206 | main() -------------------------------------------------------------------------------- /.history/requirements_20250309061752.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.history/requirements_20250309061755.txt: -------------------------------------------------------------------------------- 1 | selenium==4.17.0 2 | webdriver-manager==4.0.1 -------------------------------------------------------------------------------- /.history/requirements_20250309062118.txt: -------------------------------------------------------------------------------- 1 | selenium==4.17.0 2 | webdriver-manager==4.0.1 3 | typing_extensions>=4.0.0 -------------------------------------------------------------------------------- /.history/requirements_20250309070045.txt: -------------------------------------------------------------------------------- 1 | selenium==4.17.0 2 | webdriver-manager==4.0.1 3 | typing_extensions>=4.0.0 4 | undetected-chromedriver>=3.5.5 -------------------------------------------------------------------------------- /.history/simple_browser_20250309090652.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.history/simple_browser_20250309090656.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | SiliconFlow手机号填写工具 - 单浏览器顺序版 6 | 功能:一次只打开一个浏览器,等待用户关闭当前浏览器后再打开下一个 7 | """ 8 | 9 | import undetected_chromedriver as uc 10 | from selenium.webdriver.common.by import By 11 | from selenium.webdriver.support.ui import WebDriverWait 12 | from selenium.webdriver.support import expected_conditions as EC 13 | from selenium.webdriver.common.action_chains import ActionChains 14 | from selenium.webdriver.common.keys import Keys 15 | import time 16 | import random 17 | import os 18 | import re 19 | import sys 20 | 21 | def clean_text(text): 22 | """ 23 | 去除文本中的所有空白字符(空格、制表符、换行符等) 24 | 25 | 参数: 26 | text (str): 原始文本 27 | 28 | 返回: 29 | str: 清理后的纯文本(不包含任何空白字符) 30 | """ 31 | return ''.join(text.split()) 32 | 33 | def extract_phone_numbers(text): 34 | """ 35 | 从完全清理后的文本中提取手机号(逐字符扫描方法) 36 | 37 | 参数: 38 | text (str): 已清理的文本(无空白字符) 39 | 40 | 返回: 41 | list: 提取到的手机号列表 42 | """ 43 | # 存储找到的手机号 44 | found_phones = [] 45 | 46 | # 逐字符扫描文本 47 | i = 0 48 | while i <= len(text) - 11: # 需要至少11个字符才能形成手机号 49 | # 检查当前位置开始的11个字符是否是手机号 50 | potential_phone = text[i:i+11] 51 | 52 | # 检查是否符合中国大陆手机号的格式(1开头的11位数字) 53 | if potential_phone[0] == '1' and potential_phone.isdigit(): 54 | # 进一步验证第二位是否在3-9之间 55 | if '3' <= potential_phone[1] <= '9': 56 | found_phones.append(potential_phone) 57 | print(f"在位置 {i} 找到手机号: {potential_phone}") 58 | 59 | # 跳过这个手机号的剩余部分 60 | i += 11 61 | continue 62 | 63 | # 移动到下一个字符 64 | i += 1 65 | 66 | # 去除重复的手机号 67 | unique_phones = list(set(found_phones)) 68 | return unique_phones 69 | 70 | def fill_phone_number(phone_number): 71 | """ 72 | 打开一个浏览器并填写手机号,等待用户关闭后返回 73 | 74 | 参数: 75 | phone_number (str): 要填写的手机号 76 | 77 | 返回: 78 | bool: 是否成功 79 | """ 80 | # 创建一个临时目录作为用户数据目录 81 | user_data_dir = f"chrome_user_data_{phone_number}" 82 | os.makedirs(user_data_dir, exist_ok=True) 83 | 84 | # 创建独立的chromedriver目录 85 | driver_dir = f"chromedriver_dir_{phone_number}" 86 | os.makedirs(driver_dir, exist_ok=True) 87 | 88 | print(f"\n正在为手机号 {phone_number} 启动浏览器...") 89 | 90 | try: 91 | # Chrome选项 92 | options = uc.ChromeOptions() 93 | 94 | # 添加用户代理 95 | options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.6943.143 Safari/537.36") 96 | 97 | # 设置用户数据目录 98 | options.add_argument(f"--user-data-dir={os.path.abspath(user_data_dir)}") 99 | 100 | # 基本设置 101 | options.add_argument("--no-first-run") 102 | options.add_argument("--no-default-browser-check") 103 | options.add_argument("--no-sandbox") 104 | options.add_argument("--disable-extensions") 105 | options.add_argument("--disable-blink-features=AutomationControlled") 106 | 107 | # 初始化浏览器 108 | driver = uc.Chrome( 109 | options=options, 110 | driver_executable_path=None, 111 | headless=False, 112 | version_main=133, 113 | use_subprocess=True, 114 | cache_path=os.path.abspath(driver_dir) 115 | ) 116 | 117 | # 设置隐式等待 118 | driver.implicitly_wait(10) 119 | 120 | # 打开登录页面 121 | url = "https://account.siliconflow.cn/zh/login?redirect=https%3A%2F%2Fcloud.siliconflow.cn%2F%3F" 122 | driver.get(url) 123 | print(f"已打开登录页面") 124 | 125 | # 等待页面加载 126 | time.sleep(2) 127 | 128 | # 尝试找到并填写手机号输入框 129 | selectors = [ 130 | "//input[@placeholder='请输入手机号' or contains(@placeholder, '手机号')]", 131 | "//input[contains(@class, 'phone') or contains(@name, 'phone') or contains(@id, 'phone')]", 132 | "//input[@type='tel']" 133 | ] 134 | 135 | phone_input = None 136 | for selector in selectors: 137 | try: 138 | elements = driver.find_elements(By.XPATH, selector) 139 | if elements: 140 | phone_input = elements[0] 141 | break 142 | except: 143 | continue 144 | 145 | if phone_input: 146 | # 点击输入框 147 | phone_input.click() 148 | 149 | # 清空输入框 150 | phone_input.clear() 151 | 152 | # 输入手机号 153 | phone_input.send_keys(phone_number) 154 | print(f"已成功填写手机号: {phone_number}") 155 | 156 | # 尝试点击复选框 157 | try: 158 | # 查找复选框 159 | checkbox_selectors = [ 160 | "//input[@class='ant-checkbox-input' and @type='checkbox']", 161 | "//span[contains(@class, 'ant-checkbox')]/input[@type='checkbox']", 162 | "//input[@type='checkbox']", 163 | "//label[contains(@class, 'ant-checkbox-wrapper')]//input" 164 | ] 165 | 166 | for selector in checkbox_selectors: 167 | checkbox_elements = driver.find_elements(By.XPATH, selector) 168 | if checkbox_elements: 169 | action = ActionChains(driver) 170 | action.move_to_element(checkbox_elements[0]).click().perform() 171 | print(f"已点击复选框") 172 | break 173 | except Exception as e: 174 | print(f"点击复选框时出错: {e}") 175 | 176 | # 查找获取验证码按钮 177 | try: 178 | code_buttons = driver.find_elements(By.XPATH, "//button[contains(text(), '验证码') or contains(text(), '获取')]") 179 | if code_buttons: 180 | action = ActionChains(driver) 181 | action.move_to_element(code_buttons[0]).perform() 182 | print(f"已找到获取验证码按钮,等待手动点击") 183 | except: 184 | pass 185 | 186 | else: 187 | print(f"未找到手机号输入框") 188 | 189 | print("\n浏览器已准备就绪") 190 | print("注意: 请在完成操作后关闭浏览器窗口,系统将自动为下一个手机号打开新的浏览器") 191 | 192 | # 等待浏览器被关闭 193 | while True: 194 | try: 195 | # 简单的检查,尝试获取标题 196 | title = driver.title 197 | time.sleep(2) # 每2秒检查一次 198 | except: 199 | print(f"浏览器已关闭") 200 | break 201 | 202 | return True 203 | 204 | except Exception as e: 205 | print(f"发生错误: {e}") 206 | return False 207 | 208 | if __name__ == "__main__": 209 | print("SiliconFlow手机号填写工具 - 单浏览器顺序版") 210 | print("=" * 50) 211 | print("请输入或粘贴包含手机号的文本") 212 | print("输入完成后,请键入'END'然后按回车结束输入") 213 | print("系统将依次为每个手机号打开浏览器,关闭当前浏览器后将自动打开下一个") 214 | print("=" * 50) 215 | 216 | # 收集输入(直到遇到特定结束标记) 217 | lines = [] 218 | print("请开始输入文本(输入'END'结束):") 219 | while True: 220 | try: 221 | line = input() 222 | if line.strip() == "END": # 使用特定标记结束输入 223 | break 224 | lines.append(line) 225 | except EOFError: # 处理EOF(Ctrl+D/Ctrl+Z) 226 | break 227 | 228 | # 合并所有输入行 229 | input_text = "\n".join(lines) 230 | 231 | # 显示原始文本 232 | print("\n您输入的原始文本是:") 233 | print("-" * 50) 234 | print(input_text) 235 | print("-" * 50) 236 | print(f"原始文本长度: {len(input_text)} 字符") 237 | print(f"原始文本行数: {len(lines)} 行") 238 | 239 | # 清理文本(去除所有空格和换行) 240 | cleaned_text = clean_text(input_text) 241 | print(f"\n清理后的文本长度: {len(cleaned_text)} 字符") 242 | print("所有空格、换行和空白字符已移除") 243 | 244 | # 从清理后的文本中提取手机号 245 | phone_numbers = extract_phone_numbers(cleaned_text) 246 | 247 | # 检查是否找到手机号 248 | if not phone_numbers: 249 | print("未在输入文本中找到有效的手机号!") 250 | sys.exit(1) 251 | 252 | # 显示找到的手机号 253 | print(f"\n成功提取到 {len(phone_numbers)} 个手机号:") 254 | for i, phone in enumerate(phone_numbers): 255 | print(f"{i+1}. {phone}") 256 | 257 | # 询问用户是否继续 258 | confirm = input(f"\n是否依次为这 {len(phone_numbers)} 个手机号启动浏览器? (y/n): ") 259 | if confirm.lower() != 'y': 260 | print("已取消操作。") 261 | sys.exit(0) 262 | 263 | # 顺序处理每个手机号 264 | print(f"\n准备依次处理 {len(phone_numbers)} 个手机号...") 265 | 266 | completed = 0 267 | for i, phone in enumerate(phone_numbers): 268 | print(f"\n处理第 {i+1}/{len(phone_numbers)} 个手机号: {phone}") 269 | 270 | # 填写手机号 271 | success = fill_phone_number(phone) 272 | 273 | if success: 274 | completed += 1 275 | print(f"已完成 {completed}/{len(phone_numbers)} 个手机号") 276 | else: 277 | print(f"处理手机号 {phone} 时出错,跳过") 278 | 279 | # 最后一个手机号处理完毕 280 | if i == len(phone_numbers) - 1: 281 | print("\n所有手机号已处理完毕!") 282 | break 283 | 284 | # 提示用户下一个手机号 285 | print(f"\n下一个手机号是: {phone_numbers[i+1]}") 286 | print("关闭当前浏览器后将自动为此手机号打开新的浏览器") 287 | 288 | print("\n感谢使用!") -------------------------------------------------------------------------------- /.history/simple_cleaner_20250309081419.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.history/simple_cleaner_20250309081423.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | 简单数据清理脚本 6 | 功能:去除文本中的所有空格和换行 7 | """ 8 | 9 | def clean_text(text): 10 | """去除文本中的所有空白字符""" 11 | return ''.join(text.split()) 12 | 13 | if __name__ == "__main__": 14 | print("简单文本清理工具 - 去除所有空格和换行") 15 | print("=" * 40) 16 | print("请输入或粘贴要处理的文本(输入完成后按两次回车结束):") 17 | 18 | # 收集输入 19 | lines = [] 20 | while True: 21 | try: 22 | line = input() 23 | if not line and not lines: # 跳过开头的空行 24 | continue 25 | if not line: # 结束输入 26 | break 27 | lines.append(line) 28 | except EOFError: # 处理EOF(Ctrl+D/Ctrl+Z) 29 | break 30 | 31 | # 合并和清理文本 32 | input_text = "\n".join(lines) 33 | cleaned_text = clean_text(input_text) 34 | 35 | # 显示结果 36 | print("\n清理后的文本(所有空格和换行已移除):") 37 | print("-" * 40) 38 | print(cleaned_text) 39 | print("-" * 40) 40 | print(f"\n原始长度: {len(input_text)} 字符") 41 | print(f"清理后长度: {len(cleaned_text)} 字符") 42 | print(f"移除了 {len(input_text) - len(cleaned_text)} 个空白字符") -------------------------------------------------------------------------------- /.history/simple_cleaner_20250309081730.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | 简单数据清理脚本 6 | 功能:去除文本中的所有空格和换行 7 | """ 8 | 9 | def clean_text(text): 10 | """去除文本中的所有空白字符""" 11 | return ''.join(text.split()) 12 | 13 | if __name__ == "__main__": 14 | print("简单文本清理工具 - 去除所有空格和换行") 15 | print("=" * 40) 16 | print("请输入或粘贴要处理的文本") 17 | print("输入完成后,请键入'END'然后按回车结束输入") 18 | print("这样可以确保处理所有数据,即使其中包含空行") 19 | print("=" * 40) 20 | 21 | # 收集输入(直到遇到特定结束标记) 22 | lines = [] 23 | print("请开始输入文本(输入'END'结束):") 24 | while True: 25 | try: 26 | line = input() 27 | if line.strip() == "END": # 使用特定标记结束输入 28 | break 29 | lines.append(line) 30 | except EOFError: # 处理EOF(Ctrl+D/Ctrl+Z) 31 | break 32 | 33 | # 合并和清理文本 34 | input_text = "\n".join(lines) 35 | 36 | # 显示原始文本,帮助确认所有内容都被读取 37 | print("\n你输入的原始文本是:") 38 | print("-" * 40) 39 | print(input_text) 40 | print("-" * 40) 41 | 42 | # 清理文本 43 | cleaned_text = clean_text(input_text) 44 | 45 | # 显示结果 46 | print("\n清理后的文本(所有空格和换行已移除):") 47 | print("-" * 40) 48 | print(cleaned_text) 49 | print("-" * 40) 50 | print(f"\n原始长度: {len(input_text)} 字符") 51 | print(f"清理后长度: {len(cleaned_text)} 字符") 52 | print(f"移除了 {len(input_text) - len(cleaned_text)} 个空白字符") 53 | 54 | # 提取并显示找到的手机号 55 | phone_numbers = [] 56 | i = 0 57 | while i <= len(cleaned_text) - 11: # 需要至少11个字符才能形成手机号 58 | # 检查当前位置开始的11个字符是否是手机号 59 | potential_phone = cleaned_text[i:i+11] 60 | 61 | # 检查是否符合中国大陆手机号的格式(1开头的11位数字) 62 | if potential_phone[0] == '1' and potential_phone.isdigit(): 63 | # 进一步验证第二位是否在3-9之间 64 | if '3' <= potential_phone[1] <= '9': 65 | phone_numbers.append(potential_phone) 66 | # 跳过这个手机号的剩余部分 67 | i += 11 68 | continue 69 | 70 | # 移动到下一个字符 71 | i += 1 72 | 73 | # 去除重复的手机号 74 | unique_phones = list(set(phone_numbers)) 75 | 76 | # 显示找到的手机号 77 | if unique_phones: 78 | print("\n从清理后的文本中提取到的手机号:") 79 | for i, phone in enumerate(unique_phones): 80 | print(f"{i+1}. {phone}") 81 | print(f"共找到 {len(unique_phones)} 个手机号") -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # 默认忽略的文件 2 | /shelf/ 3 | /workspace.xml 4 | # 基于编辑器的 HTTP 客户端请求 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /.idea/autore.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SiliconFlow自动填写手机号脚本 2 | 3 | 这个Python脚本可以自动打开SiliconFlow的登录页面并填写手机号码。支持同时打开多个浏览器实例,并能自动从文本中提取手机号。脚本采用了最先进的反检测技术,包括使用专业的undetected_chromedriver库,有效绕过网站的自动化检测。 4 | 5 | ## 安装依赖 6 | 7 | 在使用脚本之前,请确保安装所有必要的依赖: 8 | 9 | ```bash 10 | pip install -r requirements.txt 11 | ``` 12 | 13 | ## 使用方法 14 | 15 | ### 批量提取模式(当前模式) 16 | 1. 运行脚本: 17 | ```bash 18 | python auto_phone_fill.py 19 | ``` 20 | 2. 脚本会提示您粘贴包含手机号的文本(可以是任意格式的文本,如聊天记录、文档等) 21 | 3. 粘贴文本后,按两次回车确认输入完成 22 | 4. 脚本会自动提取文本中的所有手机号 23 | 5. 确认提取到的手机号后,脚本会自动启动相应数量的浏览器并填写手机号 24 | 6. 脚本会保持运行状态以确保浏览器不会关闭 25 | 7. 当您完成所有操作后,按下Ctrl+C终止脚本(浏览器会保持打开状态) 26 | 27 | ### 旧版使用方法(已弃用) 28 | ~~1. 交互式输入手机号~~ 29 | ~~2. 在文件中预设手机号列表~~ 30 | 31 | ## 注意事项 32 | 33 | - 脚本默认会打开Chrome浏览器窗口,如需以无头模式运行(不显示浏览器窗口),请修改源代码中的相关设置 34 | - 浏览器会一直保持打开状态,即使在脚本终止后也不会关闭,您可以手动关闭浏览器窗口 35 | - 如果您想要终止脚本但保持浏览器窗口打开,只需按Ctrl+C即可 36 | - 网页元素定位可能会因网站变更而失效,如遇问题请根据错误信息调整XPATH选择器 37 | - 在多浏览器模式下,脚本会依次启动浏览器并填写相应的手机号码,每个浏览器之间有随机延迟以避免资源竞争 38 | - 提取手机号时使用正则表达式模式`1[3-9]\d{9}`,符合中国大陆手机号格式 39 | - 脚本会自动去除重复的手机号,每个手机号只会开启一个浏览器实例 40 | - 每个浏览器实例都会使用独立的用户数据目录,这有助于避免会话冲突和指纹追踪 41 | 42 | ## 高级反检测技术 43 | 44 | 该脚本使用了多种专业级反检测技术,有效绕过大多数网站的自动化检测: 45 | 46 | - 使用专业的`undetected_chromedriver`库代替标准Selenium(最重要的改进) 47 | - 为每个浏览器实例创建独立的用户数据目录,隔离会话状态 48 | - 使用隐身模式(Incognito)增强隐私和减少指纹 49 | - 直接输入手机号(不再模拟逐字符输入) 50 | - 多重选择器策略,提高元素定位成功率 51 | - 随机浏览器窗口大小 52 | - 随机用户代理(User-Agent) 53 | - 禁用自动化控制特征 54 | - 使用Chrome 133版本的驱动程序,匹配当前浏览器版本 -------------------------------------------------------------------------------- /__pycache__/auto_phone_fill.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nanzhexi/autore/c97dcb984de47ffe81bbb8f50c1edbbf5aac20e0/__pycache__/auto_phone_fill.cpython-310.pyc -------------------------------------------------------------------------------- /data_cleaner.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | 数据清理脚本 6 | 功能:去除文本中的所有空格、制表符、换行符等空白字符,并提取手机号 7 | """ 8 | 9 | import os 10 | import re 11 | 12 | def clean_text(text): 13 | """ 14 | 去除文本中的所有空白字符(空格、制表符、换行符等) 15 | 16 | 参数: 17 | text (str): 原始文本 18 | 19 | 返回: 20 | str: 清理后的纯文本(不包含任何空白字符) 21 | """ 22 | return ''.join(text.split()) 23 | 24 | def extract_phone_numbers(text): 25 | """ 26 | 从文本中提取中国大陆手机号 27 | 28 | 参数: 29 | text (str): 要提取手机号的文本 30 | 31 | 返回: 32 | list: 提取到的手机号列表 33 | """ 34 | phone_numbers = [] 35 | i = 0 36 | while i <= len(text) - 11: # 需要至少11个字符才能形成手机号 37 | # 检查当前位置开始的11个字符是否是手机号 38 | potential_phone = text[i:i+11] 39 | 40 | # 检查是否符合中国大陆手机号的格式(1开头的11位数字) 41 | if potential_phone[0] == '1' and potential_phone.isdigit(): 42 | # 进一步验证第二位是否在3-9之间 43 | if '3' <= potential_phone[1] <= '9': 44 | phone_numbers.append(potential_phone) 45 | # 跳过这个手机号的剩余部分 46 | i += 11 47 | continue 48 | 49 | # 移动到下一个字符 50 | i += 1 51 | 52 | # 去除重复的手机号 53 | return list(set(phone_numbers)) 54 | 55 | def clean_from_input(): 56 | """从用户输入获取文本并清理""" 57 | print("请输入或粘贴要处理的文本") 58 | print("输入完成后,请键入'END'然后按回车结束输入") 59 | print("这样可以确保处理所有数据,即使其中包含空行") 60 | 61 | lines = [] 62 | print("\n请开始输入文本(输入'END'结束):") 63 | while True: 64 | line = input() 65 | if line.strip() == "END": # 使用特定标记结束输入 66 | break 67 | lines.append(line) 68 | 69 | # 合并所有输入行 70 | input_text = "\n".join(lines) 71 | 72 | # 显示原始文本信息 73 | print(f"\n原始文本长度: {len(input_text)} 字符") 74 | print(f"原始文本行数: {len(lines)} 行") 75 | 76 | # 清理文本 77 | cleaned_text = clean_text(input_text) 78 | 79 | # 显示清理后的文本信息 80 | print(f"\n清理后的文本长度: {len(cleaned_text)} 字符") 81 | print("所有空格、换行和空白字符已移除") 82 | 83 | # 提取手机号 84 | phone_numbers = extract_phone_numbers(cleaned_text) 85 | 86 | # 显示提取到的手机号 87 | if phone_numbers: 88 | print("\n从清理后的文本中提取到的手机号:") 89 | for i, phone in enumerate(phone_numbers): 90 | print(f"{i+1}. {phone}") 91 | print(f"共找到 {len(phone_numbers)} 个手机号") 92 | else: 93 | print("\n未找到任何手机号") 94 | 95 | # 询问用户是否要查看清理后的文本 96 | show_text = input("\n是否显示清理后的文本?(y/n): ") 97 | if show_text.lower() == 'y': 98 | print("\n清理后的文本:") 99 | print("="*50) 100 | print(cleaned_text) 101 | print("="*50) 102 | 103 | # 询问用户是否要保存到文件 104 | save_to_file = input("\n是否保存到文件?(y/n): ") 105 | if save_to_file.lower() == 'y': 106 | filename = input("请输入文件名(默认为 cleaned_data.txt): ") or "cleaned_data.txt" 107 | with open(filename, 'w', encoding='utf-8') as f: 108 | f.write(cleaned_text) 109 | print(f"文件已保存为: {os.path.abspath(filename)}") 110 | 111 | # 询问是否保存提取到的手机号 112 | if phone_numbers: 113 | save_phones = input("是否保存提取到的手机号到文件? (y/n): ") 114 | if save_phones.lower() == 'y': 115 | phone_filename = input("请输入手机号文件名(默认为 phone_numbers.txt): ") or "phone_numbers.txt" 116 | with open(phone_filename, 'w', encoding='utf-8') as f: 117 | for phone in phone_numbers: 118 | f.write(phone + '\n') 119 | print(f"手机号已保存为: {os.path.abspath(phone_filename)}") 120 | 121 | return cleaned_text, phone_numbers 122 | 123 | def clean_from_file(input_file, output_file=None): 124 | """从文件读取文本并清理""" 125 | try: 126 | # 读取输入文件 127 | with open(input_file, 'r', encoding='utf-8') as f: 128 | input_text = f.read() 129 | 130 | # 显示原始文本信息 131 | print(f"\n原始文件: {input_file}") 132 | print(f"原始文本长度: {len(input_text)} 字符") 133 | 134 | # 清理文本 135 | cleaned_text = clean_text(input_text) 136 | 137 | # 显示清理后的文本信息 138 | print(f"\n清理后的文本长度: {len(cleaned_text)} 字符") 139 | print("所有空格、换行和空白字符已移除") 140 | 141 | # 提取手机号 142 | phone_numbers = extract_phone_numbers(cleaned_text) 143 | 144 | # 显示提取到的手机号 145 | if phone_numbers: 146 | print("\n从清理后的文本中提取到的手机号:") 147 | for i, phone in enumerate(phone_numbers): 148 | print(f"{i+1}. {phone}") 149 | print(f"共找到 {len(phone_numbers)} 个手机号") 150 | else: 151 | print("\n未找到任何手机号") 152 | 153 | # 如果指定了输出文件,保存清理后的文本 154 | if output_file: 155 | with open(output_file, 'w', encoding='utf-8') as f: 156 | f.write(cleaned_text) 157 | print(f"清理后的文本已保存到: {output_file}") 158 | 159 | # 如果找到了手机号,询问是否保存 160 | if phone_numbers: 161 | save_phones = input("是否保存提取到的手机号到文件? (y/n): ") 162 | if save_phones.lower() == 'y': 163 | phone_filename = input("请输入手机号文件名(默认为 phone_numbers.txt): ") or "phone_numbers.txt" 164 | with open(phone_filename, 'w', encoding='utf-8') as f: 165 | for phone in phone_numbers: 166 | f.write(phone + '\n') 167 | print(f"手机号已保存为: {os.path.abspath(phone_filename)}") 168 | 169 | return cleaned_text, phone_numbers 170 | 171 | except Exception as e: 172 | print(f"处理文件时出错: {e}") 173 | return None, None 174 | 175 | def main(): 176 | """主函数""" 177 | print("文本数据清理与手机号提取工具") 178 | print("=" * 40) 179 | 180 | while True: 181 | print("\n请选择操作:") 182 | print("1. 输入或粘贴文本进行处理") 183 | print("2. 从文件读取文本进行处理") 184 | print("3. 退出") 185 | 186 | choice = input("请选择 [1/2/3]: ") 187 | 188 | if choice == '1': 189 | clean_from_input() 190 | elif choice == '2': 191 | input_file = input("请输入源文件路径: ") 192 | save_option = input("是否保存处理后的文本到文件? (y/n): ") 193 | 194 | if save_option.lower() == 'y': 195 | output_file = input("请输入目标文件路径(默认为 cleaned_data.txt): ") or "cleaned_data.txt" 196 | clean_from_file(input_file, output_file) 197 | else: 198 | clean_from_file(input_file) 199 | elif choice == '3': 200 | print("感谢使用,再见!") 201 | break 202 | else: 203 | print("无效的选择,请重试。") 204 | 205 | if __name__ == "__main__": 206 | main() -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | # 这是一个示例 Python 脚本。 2 | 3 | # 按 Shift+F10 执行或将其替换为您的代码。 4 | # 按 双击 Shift 在所有地方搜索类、文件、工具窗口、操作和设置。 5 | 6 | 7 | def print_hi(name): 8 | # 在下面的代码行中使用断点来调试脚本。 9 | print(f'Hi, {name}') # 按 Ctrl+F8 切换断点。 10 | 11 | 12 | # 按间距中的绿色按钮以运行脚本。 13 | if __name__ == '__main__': 14 | print_hi('PyCharm') 15 | 16 | # 访问 https://www.jetbrains.com/help/pycharm/ 获取 PyCharm 帮助 17 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | selenium==4.17.0 2 | webdriver-manager==4.0.1 3 | typing_extensions>=4.0.0 4 | undetected-chromedriver>=3.5.5 -------------------------------------------------------------------------------- /simple_cleaner.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | 简单数据清理脚本 6 | 功能:去除文本中的所有空格和换行 7 | """ 8 | 9 | def clean_text(text): 10 | """去除文本中的所有空白字符""" 11 | return ''.join(text.split()) 12 | 13 | if __name__ == "__main__": 14 | print("简单文本清理工具 - 去除所有空格和换行") 15 | print("=" * 40) 16 | print("请输入或粘贴要处理的文本") 17 | print("输入完成后,请键入'END'然后按回车结束输入") 18 | print("这样可以确保处理所有数据,即使其中包含空行") 19 | print("=" * 40) 20 | 21 | # 收集输入(直到遇到特定结束标记) 22 | lines = [] 23 | print("请开始输入文本(输入'END'结束):") 24 | while True: 25 | try: 26 | line = input() 27 | if line.strip() == "END": # 使用特定标记结束输入 28 | break 29 | lines.append(line) 30 | except EOFError: # 处理EOF(Ctrl+D/Ctrl+Z) 31 | break 32 | 33 | # 合并和清理文本 34 | input_text = "\n".join(lines) 35 | 36 | # 显示原始文本,帮助确认所有内容都被读取 37 | print("\n你输入的原始文本是:") 38 | print("-" * 40) 39 | print(input_text) 40 | print("-" * 40) 41 | 42 | # 清理文本 43 | cleaned_text = clean_text(input_text) 44 | 45 | # 显示结果 46 | print("\n清理后的文本(所有空格和换行已移除):") 47 | print("-" * 40) 48 | print(cleaned_text) 49 | print("-" * 40) 50 | print(f"\n原始长度: {len(input_text)} 字符") 51 | print(f"清理后长度: {len(cleaned_text)} 字符") 52 | print(f"移除了 {len(input_text) - len(cleaned_text)} 个空白字符") 53 | 54 | # 提取并显示找到的手机号 55 | phone_numbers = [] 56 | i = 0 57 | while i <= len(cleaned_text) - 11: # 需要至少11个字符才能形成手机号 58 | # 检查当前位置开始的11个字符是否是手机号 59 | potential_phone = cleaned_text[i:i+11] 60 | 61 | # 检查是否符合中国大陆手机号的格式(1开头的11位数字) 62 | if potential_phone[0] == '1' and potential_phone.isdigit(): 63 | # 进一步验证第二位是否在3-9之间 64 | if '3' <= potential_phone[1] <= '9': 65 | phone_numbers.append(potential_phone) 66 | # 跳过这个手机号的剩余部分 67 | i += 11 68 | continue 69 | 70 | # 移动到下一个字符 71 | i += 1 72 | 73 | # 去除重复的手机号 74 | unique_phones = list(set(phone_numbers)) 75 | 76 | # 显示找到的手机号 77 | if unique_phones: 78 | print("\n从清理后的文本中提取到的手机号:") 79 | for i, phone in enumerate(unique_phones): 80 | print(f"{i+1}. {phone}") 81 | print(f"共找到 {len(unique_phones)} 个手机号") --------------------------------------------------------------------------------