使用SeleniumBase的uc=True选项启动浏览器时程序冻结的问题求助
使用SeleniumBase的uc=True选项启动浏览器时程序冻结的问题求助
大家好,我最近在爬取一个带有Cloudflare机器人验证的网站,之前用undetected_chromedriver搭配便携版Chrome.exe尝试,但始终没法绕过验证。所以转用SeleniumBase试试,结果在初始化SB对象的时候遇到了麻烦。
我用SB(uc=True, agent=user_agent_cycle, binary_location=chromedriver_path)这个写法启动浏览器,程序运行到with语句时直接冻结了,控制台只输出了一行:
<itertools.cycle object at 0x0000027605C89D80>
后面的print(1)完全没执行,程序就卡在那里不动了。
下面是我的完整代码,麻烦各位帮忙看看哪里出问题了:
from seleniumbase import SB chromedriver_path = "C:\\temp\\GoogleChromePortable64-132\\App\\Chrome-bin\\chrome.exe" import random import itertools def user_agent_rotator(user_agent_list): # shuffle the User Agent list random.shuffle(user_agent_list) # rotate the shuffle to ensure all User Agents are used return itertools.cycle(user_agent_list) # define Chrome options #options = SB.ChromeOptions() # create a User Agent list user_agents = [ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36", # ... add more User Agents ] # initialize a generator for the User Agent rotator user_agent_cycle = user_agent_rotator(user_agents) print(user_agent_cycle) with SB(uc=True,agent=user_agent_cycle,binary_location=chromedriver_path) as sb: print(1) sb.open("https://google.com/ncr") print(2) sb.type('[title="Search"]', "SeleniumBase GitHub page\n") print(3) sb.click('[href*="github.com/seleniumbase/"]') sb.save_screenshot_to_logs() # ./latest_logs/ print(sb.get_page_title())
备注:内容来源于stack exchange,提问作者RobM
相关产品推荐
相关产品推荐

