使用Python Selenium爬取EGX网站时遇USB错误及访问受限问题咨询
Selenium爬取埃及证券交易所官网的错误排查
关于USB错误的说明
你碰到的USB: usb_service_win.cc:105 SetupDiGetDeviceProperty...错误,是ChromeDriver在Windows系统里读取USB设备属性时的小故障,属于兼容性问题,这个错误本身不会直接导致网站打不开,真正的问题出在网站的反爬机制上。
为什么手动能打开但爬虫不行?
网站能识别出你用的是自动化工具(Selenium/BeautifulSoup),核心原因包括:
- Selenium默认的Chrome实例带有明显的自动化标识,网站的JS脚本可以检测到
- 爬虫请求缺少浏览器自动携带的正常请求头(比如User-Agent、语言设置)
- 没有模拟人类浏览的行为(比如页面加载后的等待、滚动操作)
解决办法
- 隐藏自动化特征:给ChromeOptions添加参数,让浏览器看起来更像手动打开的:
options.add_argument('--disable-blink-features=AutomationControlled') options.add_experimental_option('excludeSwitches', ['enable-automation']) options.add_experimental_option('useAutomationExtension', False) - 设置正常的请求头:模拟常用浏览器的User-Agent:
options.add_argument('user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36') - 添加页面等待:等页面加载完成再操作,避免因未渲染完全导致的异常:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By driver.get("https://www.egx.com.eg/ar/homepage.aspx") # 等待页面body元素加载完成,最多等10秒 WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.TAG_NAME, 'body'))) - 检查网络环境:确认你的IP没有被网站封禁,必要时可以更换网络试试。
内容的提问来源于stack exchange,提问作者Bassel Fathy
相关产品推荐
相关产品推荐

