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

Selenium爬取Godaddy域名价格失败:页面无法加载(浏览器正常)

问题描述
  • 目标:获取域名bjmtuc.club在GoDaddy印度站点的价格(₹149.00),或获取页面源码用于BS4解析
  • 异常:Selenium打开目标页面后无法加载,但普通浏览器可正常访问
  • 截图情况:Selenium启动的浏览器页面处于加载停滞状态
  • 当前使用代码:
import time
import chromedriver_autoinstaller
from selenium import webdriver

chromedriver_autoinstaller.install()  # 检查并自动安装对应版本的chromedriver

driver = webdriver.Chrome()
driver.get('https://in.godaddy.com/domainsearch/find?checkAvail=1&domainToCheck=bjmtuc.club#')

time.sleep(100)
解决方案

1. 伪装浏览器绕过反爬检测

GoDaddy会识别Selenium的自动化特征,添加启动参数伪装成普通浏览器即可正常加载页面:

import time
import chromedriver_autoinstaller
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chromedriver_autoinstaller.install()

# 配置浏览器选项,禁用自动化特征
options = Options()
options.add_argument("--disable-blink-features=AutomationControlled")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)

driver = webdriver.Chrome(options=options)
# 进一步修改navigator.webdriver属性,彻底伪装
driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")

driver.get('https://in.godaddy.com/domainsearch/find?checkAvail=1&domainToCheck=bjmtuc.club#')
time.sleep(5)  # 合理缩短等待时间

# 获取页面源码,可直接用于BS4解析
page_source = driver.page_source
# 这里可以添加BS4解析代码,示例:
# from bs4 import BeautifulSoup
# soup = BeautifulSoup(page_source, 'html.parser')
# price = soup.find(...)

driver.quit()

2. 直接调用官方API(更高效)

无需加载完整页面,直接调用GoDaddy的查询接口,返回JSON数据后提取价格,速度更快且稳定性更高:

import requests

# 伪装请求头,模拟普通浏览器访问
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36',
    'Accept-Language': 'en-IN,en;q=0.9'
}

# 官方精确查询接口
url = 'https://in.godaddy.com/domainsapi/v1/search/exact?domainToCheck=bjmtuc.club'
response = requests.get(url, headers=headers)
data = response.json()

# 提取价格信息
if data['ExactMatchDomain']['IsAvailable']:
    price = data['ExactMatchDomain']['PriceInfo']['CurrentPrice']
    currency = data['ExactMatchDomain']['PriceInfo']['Currency']
    print(f"{currency} {price}")  # 输出示例:₹149.00
else:
    print("该域名已被注册")

内容的提问来源于stack exchange,提问作者Gaming Fury

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 23:55:18