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

使用Selenium与Python自动加购JBL音箱时遇网络访问问题求助

Troubleshooting "This site can't be reached" with Selenium + Amazon India

Hey there! Let's work through the issue you're hitting while trying to automate adding that blue JBL speaker to your Amazon cart with Python and Selenium. First, let's recap your goal:

  • Navigate to the specific JBL speaker product page
  • Select the blue variant of the speaker
  • Click the "Add to Cart" button

But right now, you're stuck with the This site can't be reached error when trying to access the link. Here are practical fixes and checks to resolve this:

1. Start with Basic Network Checks

Before tweaking code, rule out simple network problems:

  • Try opening the product page manually in your regular browser. If it fails here too, you're likely facing regional restrictions, firewall blocks, or ISP limitations. You might need a proxy or VPN that works with Amazon India.
  • If manual access works, the issue is specific to how Selenium is interacting with the site.

2. Fix Selenium's Browser Configuration

Selenium's default setup doesn't mimic a real user's browser perfectly, which can trigger access blocks:

  • Add a realistic User-Agent string to avoid being flagged as a bot:
    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    
    chrome_options = Options()
    # Mimic a modern Chrome browser on Windows
    chrome_options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36")
    driver = webdriver.Chrome(options=chrome_options)
    driver.get("https://www.amazon.in/dp/B010RWAIAC/ref=twister_B07D5KL6TC?_encoding=UTF8&th=1")
    
  • Configure a proxy if your region blocks Amazon India:
    Add this line to your options (replace with your valid proxy details):
    chrome_options.add_argument('--proxy-server=http://your-proxy-address:port')
    

3. Bypass Amazon's Anti-Scraping Measures

Amazon has strict anti-bot systems that often detect vanilla Selenium. Try using undetected-chromedriver—it's built to avoid these detections:

  • First install it via pip:
    pip install undetected-chromedriver
    
  • Then use it in your code (with bonus example steps for selecting the blue speaker and adding to cart):
    import undetected_chromedriver as uc
    
    # Initialize the driver (handles anti-detection automatically)
    driver = uc.Chrome()
    driver.get("https://www.amazon.in/dp/B010RWAIAC/ref=twister_B07D5KL6TC?_encoding=UTF8&th=1")
    
    # Select the blue speaker (adjust the element locator if needed)
    blue_option = driver.find_element("xpath", "//input[@aria-label='Blue']")
    blue_option.click()
    
    # Click Add to Cart
    add_to_cart_btn = driver.find_element("id", "add-to-cart-button")
    add_to_cart_btn.click()
    

Amazon sometimes retires product links if the item is discontinued or the page is updated:

  • Search for the product ID B010RWAIAC on Amazon India to confirm the item is still available and the link hasn't changed.

内容的提问来源于stack exchange,提问作者praveenkumar jami

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.29 09:02:37