我正在尝试开发一个网络爬虫,从 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
任何人都可以建议如何防止这种情况发生吗?这是Python错误吗?