Ich bin neu bei Python und ich brauche Hilfe zum Scraping aller Links mit einem bestimmten Schlüsselwort. Das Problem ist, dass ich folgende Fehlermeldung bin immer:Python Scrape Links Schlüsselwort
if "air-max" in link["href"]: ^ IndentationError: expected an indented block.
Hier ist mein Code
import requests
import time
from bs4 import BeautifulSoup
headers = {"Content-Type": "application/x-www-form-urlencoded;
charset=UTF-8","X-Requested-With": "XMLHttpRequest","User-Agent":
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/56.0.2924.87 Safari/537.36"}
for i in range(0,4):
url = "https://www.aw-lab.com/shop/uomo/scarpe?p={}".format(i)
r = requests.get(url)
soup = BeautifulSoup(r.content, "html.parser")
all_links = soup.find_all("a")
for link in all_links:
if link.has_key('href'):
if "air-max" in link["href"]:
print(link["href"])
Sie müssen Ihren Code einrücken. Stellen Sie sicher, dass Sie dem Stil folgen, überprüfen Sie, ob Sie überall an den richtigen Stellen Leerzeichen oder Tabulatoren haben. – lll