Python 为什么在尝试使用selenium webdriver刮取数据时会出现此错误(缩进错误:意外缩进)?

Python 为什么在尝试使用selenium webdriver刮取数据时会出现此错误(缩进错误:意外缩进)?,python,selenium,Python,Selenium,我正试图开发一个webscraper,从StockX收集有关运动鞋的信息。这是我的密码 def SneakersInfoScraper(): # Basic sneaker information time.sleep(2) driver = webdriver.Chrome(path) driver.get("https://stockx.com/nike-air-air-jordan-3-jth") Model_name =

我正试图开发一个webscraper,从StockX收集有关运动鞋的信息。这是我的密码

 
def SneakersInfoScraper():
    # Basic sneaker information

    time.sleep(2)
    driver = webdriver.Chrome(path)

    driver.get("https://stockx.com/nike-air-air-jordan-3-jth")
    Model_name = driver.find_element_by_xpath(
        '//*[@id="product-header"]/div[1]/div/h1'
    ).text
    # Retrieves the name of the Model
    print(Model_name)
    print("=" * 50)

    Color_Sneaker = driver.find_element_by_xpath('//div[@class="detail"][2]/span').text
    # Retrieves the color of the sneaker
    print(Color_Sneaker)
    print("=" * 50)

    Retail_Price = driver.find_element_by_xpath('//div[@class="detail"][3]/span').text
    # Retrieves the release date of the model
    print(Retail_Price)
    print("=" * 50)

    Release_date = driver.find_element_by_xpath('//div[@class="detail"][4]/span').text
    # Retrieves the release date of the model
    print(Release_date)
    print("=" * 50)

    OtherPriceInfo = driver.find_elements_by_xpath('//div[@class="gauges"]')

    for Each_Price_Info in OtherPriceInfo:
        Price_Premium = Each_Price_Info.find_element_by_xpath(
            '//*[@id="root"]/div[1]/div[2]/div[2]/div[8]/div/div/div/div[3]/div[2]/div[2]/div[3]'
        ).text

    print(Price_Premium)
    print("=" * 50)
它像黄油一样平滑工作,直到它碰到OtherPriceInfo变量,我设置了for循环。在输出中,我可以看到我的格式被完全弄乱了,我不知道为什么。 错误:

...     print("=" * 50)
...     OtherPriceInfo = driver.find_elements_by_xpath('//div[@class="gauges"]')
...     for Each_Price_Info in OtherPriceInfo:
...         Price_Premium = Each_Price_Info.find_element_by_xpath(
...             '//*[@id="root            '//*[@id="root     div/d            '//*[@id="root            '//*[@id="ro
  File "<stdin>", line 27
    '//*[@id="root            '//*[@id="root     div/d            '//*[@id="root            '//*[@id="ro
                                 ^
SyntaxError: invalid syntax
>>>     print(Price_Premium)
  File "<stdin>", line 1
    print(Price_Premium)
    ^
IndentationError: unexpected indent
>>>     print("=" * 50)
  File "<stdin>", line 1
    print("=" * 50)
    ^
IndentationError: unexpected indent
。。。打印(“=”*50)
...     OtherPriceInfo=driver.通过xpath('//div[@class=“gauges”]”查找元素
...     对于其他价格信息中的每个价格信息:
...         Price\u Premium=每个\u Price\u Info.find\u元素\u by\u xpath(
…'/*[@id=“root”/*[@id=“root div/d'/*[@id=“root”/*[@id=“ro
文件“”,第27行
'//*[@id=“root”/*[@id=“root div/d'/*[@id=“root”/*[@id=“ro
^
SyntaxError:无效语法
>>>印刷品(价格溢价)
文件“”,第1行
印刷品(价格溢价)
^
缩进错误:意外缩进
>>>打印(“=”*50)
文件“”,第1行
打印(“=”*50)
^
缩进错误:意外缩进
有人能建议如何防止这种情况发生吗?这是python错误吗?

检查两个函数,从视觉上看,它们在缩进方面是相同的,但在空间方面在逻辑上是不同的…因此需要使用这些类型的编辑器,它们可以分别显示空间和选项卡空间


因此,请再次检查您的代码…这是大多数python开发人员经常遇到的问题。我找到了解决此问题的方法。

发布的代码
'/*[@id=“root”]
与错误
'/*[@id>不匹配=根“
。请向我们显示实际代码。不,我不是,我直接从文件运行,输出显示在shell中。如果直接从文件运行,为什么会显示
文件
?我不确定。我使用VSCODE,可以逐行运行代码。我发布的代码与我运行的代码完全相同。我没有将其粘贴到shell中。