You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Colab使用Selenium webdriver爬取网站报'module' object is not callable错误

报错原因

你遇到的'module' object is not callable报错中文含义为**'模块'对象不可调用**,触发该问题的核心错误有2处:

  • 类名拼写错误:webdriver.chrome()中chrome为小写,对应Selenium内部的模块对象,不是可调用的Chrome驱动类,正确可调用的类名是大写开头的webdriver.Chrome()
  • 冗余重复初始化:你已经通过wd = webdriver.Chrome('chromedriver',options=options)完成了驱动实例的创建,后续重复初始化驱动的代码属于无效冗余代码。
修复后可直接在Google Colab运行的完整代码
from selenium import webdriver
import requests
from bs4 import BeautifulSoup
import pandas as pd

# 安装chromium浏览器、对应驱动和selenium依赖
!apt-get update
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin
!pip install selenium

# 配置无头模式运行参数
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')

# 初始化驱动并访问目标页面
wd = webdriver.Chrome('chromedriver', options=options)
wd.get("https://www.goibibo.com/hotels/highland-park-hotel-in-trivandrum-1383427384655815037/?hquery={%22ci%22:%2220211209%22,%22co%22:%2220211210%22,%22r%22:%221-2-0%22,%22ibp%22:%22v15%22}&hmd=766931490eb7863d2f38f56c6185a1308de782c89dfeeea59d262b827ca15441bf50472cbfdc1ee84aeed8af756809a2e89cfd6eaea0fa308c1ca839e8c313d016ac0f5948658353cf30f1cd83050fd8e6adb2e55f2a5470cadeb0c28b7becc92ac44d81966b82408effde826d40fbff47525e09b5f145e321fe6d104e12933c066323798e33a911e0cbed7312fc1634f8f92fe502c8602556c9a02f34c047d04ff1400c995799156776c1a04e218d6486493edad5b0f7e51a5ea25f5f1cb4f5ed497ee9368137f6ec73b3b1166ee7c1a885920b90c98542e0270b4fa9004005cfe87a4d1efeaedc8e33a848f73345f09bec19153e8bf625cc7f9216e692a1bcc313e7f13a7fc091328b1fb43598bd236994fdc988ab35e70cf3a5d1856c0b0fa9794b23a1a958a5937ac6d258d121a75b7ce9fc70b9a820af43a8e9a3f279be65b5c6fbfff2ba20bfb0f3e3ee425f0b930bf671c50878a540c6a9003b197622b6ab22ae39e07b5174cb12bebbcd2a132bb8570e01b9e253c1bd83cb292de97a&cc=IN&reviewType=gi&vcid=3877384277955108166&srpFilters={%22type%22:[%22Hotel%22]}")
补充说明

如果后续升级到Selenium 4.6及以上版本,无需手动指定chromedriver路径,也无需执行!cp /usr/lib/chromium-browser/chromedriver /usr/bin命令,Selenium会自动匹配对应版本的驱动。

内容的提问来源于stack exchange,提问作者ankeet jena

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 10:45:07