interface31
Goto Top

EAN Code für große Anzahl an Artikel ermitteln

Hi,

Habe versucht meine Artikel wo ich nur den Hersteller und Model mit Config habe den EAN zu ermitteln.
Leider gelingt mir dies nicht ganz über ICECAT oder Google.
Hat jemand vielleicht eine Idee wie ich den EAN von mehreren Artikel ermitteln kann nur mittels Herstellername, Model und Ausstattung?

Habe es ansatzweise mit diesem Code versucht umzusetzen aber ist nicht zu 100% erfolgreich

import pandas as pd
import openpyxl
import requests
import time
from bs4 import BeautifulSoup

# create a Workbook object for the input file
wb = openpyxl.load_workbook('/import_XLS/product_names.xlsx')  

# get the first worksheet
ws = wb.active

# create a Pandas DataFrame from the worksheet
df = pd.DataFrame(ws.values)

# add column headers (assuming they're in the first row) 
df.columns = df.iloc[0]

# remove the first row (the headers)
df = df[1:]

# add EAN codes to new column in DataFrame
ean_list = []
for name in df['Product Name']:  
    query = name + " ean"  
    response = requests.get("https://icecat.biz/search?q=" + query)  
    soup = BeautifulSoup(response.text, 'html.parser')  
    result = soup.find_all('div', class_='BNeawe iBp4i AP7Wnd')  
    if len(result) > 1 and "ean" in result[1].text:  
        ean = result[1].text.split("ean ")[-1].split()[0]  
    else:
        ean = ''  
    ean_list.append(ean)
    time.sleep(10.5)  # to avoid hitting the rate limit of the API
df['EAN Code'] = ean_list  

# write DataFrame to a new Excel file
writer = pd.ExcelWriter('/import_XLS/product_names_EAN.xlsx', engine='xlsxwriter')  
df.to_excel(writer, index=False)
writer.save()

Content-Key: 6678654998

Url: https://administrator.de/contentid/6678654998

Printed on: April 27, 2024 at 15:04 o'clock

Member: michi1983
michi1983 Apr 07, 2023 at 13:06:13 (UTC)
Goto Top
Hallo,

zu wieviel Prozent ist es erfolgreich?
Wo liegt das Problem bei den fehlenden Prozent?

Gruß
Member: interface31
interface31 Apr 07, 2023 at 16:36:48 (UTC)
Goto Top
Hi,

Problem ist das ohne eindeutigen EAN oder GTIN Nummer nicht wirklich den Artikel zuordnen kannst.
Wenn ich z.Bsp.nach den EAN für DELL Latitude E5250 nur suchen läßt findet er natürlich einige davon da dieser Artikel in zig Konfigurationen hergestellt wird.
Könnte jetzt natürlich noch dazu sagen das mit 8GB RAM, i5-5300U, 500GB SSD dann wäre es etwas eingeschränkter aber auch nicht zu 100% da ich nie alle Infos habe.
Jetzt war mein nächster Ansatzpunkt ok dann gib mir den ersten Link wenigstens dann habe ich mal den ersten Treffer wo zu 50% paßt.
Mittels Google war es ganz ok, wollte aber den Openkatalog von Icecat verwenden da hier viel drin sind und die EANs und GTIN hinterlegt sind womit ich weiter hätte abgleichen können.
Aber hier kann ich die Daten nicht abgreifen.
Vielleicht hat jemand noch eine Idee?

cu
Mitglied: 6247018886
6247018886 Apr 07, 2023 updated at 16:40:02 (UTC)
Goto Top
Einfach zu parsen, oder gleich die API
https://www.ean-search.org/

Cheers briggs
Member: interface31
interface31 Apr 07, 2023 at 18:11:31 (UTC)
Goto Top
Da drüber habe ich auch versucht leider ohne erfolg.
Genauso mit dieser API.

Mit den ersten Link aus Google geht es aber ist halt auch nicht so doll.

import pandas as pd
import openpyxl
import requests
import time
from bs4 import BeautifulSoup
import urllib3
import json
import axios

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

# create a Workbook object for the input file
wb = openpyxl.load_workbook('/import_XLS/product_names.xlsx')  

# get the first worksheet
ws = wb.active

# create a Pandas DataFrame from the worksheet
df = pd.DataFrame(ws.values)

# add column headers (assuming they're in the first row) 
df.columns = df.iloc[0]

# remove the first row (the headers)
df = df[1:]

link_list = []

for index, row in df.iterrows():

    # get the product name from the 'Product Name' column of the row 
    name = row['Product Name']  

    try:
        query = f"{name} site:amazon.com"  
        options = {
            method: 'GET',  
            url: 'https://amazon-web-scraping-api.p.rapidapi.com/products/search',  
            params: {criteria: query, page: '1', countryCode: 'US', languageCode: 'EN'},  
            headers: {
                'X-RapidAPI-Key': '9ea1bc4msh778ba1515dfp1fd33djsn6e142bb10213',  
                'X-RapidAPI-Host': 'amazon-web-scraping-api.p.rapidapi.com'  
            }
        }

        response = axios.request(options)
        data = response.data
        soup = BeautifulSoup(data, 'html.parser')  
        link = soup.find_all('a')[0]['href']  
        link_list.append(link)
    except:
        link_list.append('')  

    time.sleep(10.5)  # to avoid hitting the rate limit of the API

df['Link'] = link_list  

# write DataFrame to a new Excel file
writer = pd.ExcelWriter('/import_XLS/product_names_link.xlsx',  
                        engine='xlsxwriter')  
df.to_excel(writer, index=False)
writer._save()
Member: Kraemer
Kraemer Apr 07, 2023 at 20:01:56 (UTC)
Goto Top
Zitat von @interface31:

Da drüber habe ich auch versucht leider ohne erfolg.
Genauso mit dieser API.

den Versuch würde ich gerne sehen. Ein schneller Test rein aus Neugier von mir war sehr erfolgreich
Mitglied: 6247018886
6247018886 Apr 07, 2023 updated at 20:54:45 (UTC)
Goto Top
Zitat von @Kraemer:
den Versuch würde ich gerne sehen. Ein schneller Test rein aus Neugier von mir war sehr erfolgreich

Dito hier ebenfalls! Einfacher geht's ja nun wirklich nicht ...
https://www.ean-search.org/ean-api-intro.html
Member: interface31
interface31 Apr 08, 2023 at 09:20:07 (UTC)
Goto Top
Keine Ahnung er zieht mir keine EAN in das Sheet wenn ich mit den Produktnamen Suche.
Bei einigen Produkten paßt es natürlich nicht, da nicht eindeutig.
Wenn ich nach DELL Latitude 5280 suche kommen zig Vorschläge, muß die Suche erweitern auf CPU und RAM am besten noch.
Habe mich auf Icecat fixiert da mehr Infos hinterlegt sind.
Mit ean-search erhalte ich keine Infos
Hat mein Code einen Fehler?

import pandas as pd
import openpyxl
import time
import re
import requests
from bs4 import BeautifulSoup

# create a Workbook object for the input file
wb = openpyxl.load_workbook('/import_XLS/product_names.xlsx')  

# get the first worksheet
ws = wb.active

# create a Pandas DataFrame from the worksheet
df = pd.DataFrame(ws.values)

# add column headers (assuming they're in the first row) 
df.columns = df.iloc[0]

# remove the first row (the headers)
df = df[1:]

ean_list = []
link_list = []

for index, row in df.iterrows():

    # get the product name from the 'Product Name' column of the row 
    name = row['Product Name']  

    # search with ean-search.org
    url = 'https://www.ean-search.org/perl/ean_search.cgi?q=' + name  
    headers = {'User-Agent': 'Mozilla/5.0'}  
    res = requests.get(url, headers=headers)
    soup = BeautifulSoup(res.text, 'html.parser')  
    ean = soup.find('span', {'class': 'resultEan'})  
    link = soup.find('a', {'class': 'resultUrl'})  

    if ean:
        ean_list.append(ean.text.strip())
    else:
        ean_list.append(None)

    if link:
        link_list.append(link['href'].strip())  
    else:
        link_list.append(None)

    time.sleep(10)  # to avoid hitting the rate limit of the API

# ensure that the ean_list and link_list have the same length as the DataFrame index
for i in range(len(df) - len(ean_list)):
    ean_list.append(None)
    link_list.append(None)

df['EAN'] = ean_list  
df['Link'] = link_list  

# write DataFrame to a new Excel file
writer = pd.ExcelWriter('/import_XLS/product_names_ean.xlsx',  
                        engine='xlsxwriter')  
df.to_excel(writer, index=False)
writer._save()
Mitglied: 6247018886
Solution 6247018886 Apr 08, 2023 updated at 10:39:08 (UTC)
Goto Top
Mit ean-search erhalte ich keine Infos
Du hast ja auch nicht die API benutzt ... Siehe Link oben der Code dort klappt einwandfrei.

Wenn man es manuell von deren Seite "klauben" will, geht z.B. so aber halt auch nur begrenzt bis sie dich sperren, => API Key holen .
import requests,re
search = "Samsung SSD 980 Pro 1TB"  
baseurl = "https://www.ean-search.org"  
raw = requests.get(baseurl,params={"q" : search},headers={"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:109.0) Gecko/20100101 Firefox/111.0"})  
raw.encoding = raw.apparent_encoding
results = re.finditer('href="/ean/(\d+)[^>]*>([^<]+)',raw.text)  
for m in results:
    print('%s : %s' % (m.group(1),m.group(2)))  
Member: interface31
interface31 Apr 09, 2023 at 09:20:30 (UTC)
Goto Top
Frohe Ostern face-smile
Schaue ich mir mal an, mein Problem ist halt das ich nicht immer die eindeutige Bezeichnung habe.
Gerade bei z.Bsp. DELL Latitude 5280 gibt ja ja zig Ausstattungen und dann Keyboard Layouts.
Selbst wenn ich teilweise die Infos habe ist es kein 100% Treffer mit etwas Glück.
Wollte daher eher icecat verwenden da die Openversion für mich reichen würde.

cu
Mitglied: 6247018886
6247018886 Apr 09, 2023 updated at 09:32:32 (UTC)
Goto Top
Zitat von @interface31:

mein Problem ist halt das ich nicht immer die eindeutige Bezeichnung habe.
Gerade bei z.Bsp. DELL Latitude 5280 gibt ja ja zig Ausstattungen und dann Keyboard Layouts.
Naja dann musst du die halt dazu schreiben oder die Hersteller ArtikelNr. nehmen.

Selbst wenn ich teilweise die Infos habe ist es kein 100% Treffer mit etwas Glück.
Das ist eben so wenn man keine exakten Daten wie die Hersteller Produktnummer hat können auch keine exakten Daten zurückgeliefert werden.
So oder so musst du die EANs bei dieser Art Suche eh alle von Hand nachkontrollieren, oder du besorgst dir die Datenbank des jeweiligen Herstellers und gleichst damit ab.
Oder du probierst mal die ChatGPT/Bard API.
Member: interface31
interface31 Apr 09, 2023 at 09:50:32 (UTC)
Goto Top
Danke hat mir geholfen.
Habe es ein wenig abgeändert, so das der Name des gefunden Produktes und der Hyperlink dazu kopiert wird.
Leider hat finde ich bei ean-search nicht alles, konnte bei www.upcitemdb.com noch was mehr abgreifen.
Vielleicht hilft es den einen oder anderen auch


import pandas as pd
import openpyxl
import time
import re
import requests
from bs4 import BeautifulSoup

# create a Workbook object for the input file
wb = openpyxl.load_workbook('/import_XLS/product_names.xlsx')  

# get the first worksheet
ws = wb.active

# create a Pandas DataFrame from the worksheet
df = pd.DataFrame(ws.values)

# add column headers (assuming they're in the first row) 
df.columns = df.iloc[0]

# remove the first row (the headers)
df = df[1:]

ean_list = []
link_list = []

for index, row in df.iterrows():

    # get the product name from the 'Product Name' column of the row 
    name = row['Product Name']  

    # search with ean-search.org
    search = name
    baseurl = "https://www.ean-search.org"  
    raw = requests.get(baseurl, params={"q": search}, headers={"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:109.0) Gecko/20100101 Firefox/111.0"})  
    raw.encoding = raw.apparent_encoding
    soup = BeautifulSoup(raw.text, 'html.parser')  
    a_tag = soup.find('a', href=re.compile('/ean/\d+'))  
    ean = a_tag.text if a_tag else None
    link = f"{baseurl}{a_tag['href']}" if a_tag else None  

    ean_list.append(ean)
    link_list.append(link)

    time.sleep(10)  # to avoid hitting the rate limit of the API

# ensure that the ean_list and link_list have the same length as the DataFrame index
for i in range(len(df) - len(ean_list)):
    ean_list.append(None)
    link_list.append(None)

df['EAN'] = ean_list  
df['Link'] = link_list  

# write DataFrame to a new Excel file
writer = pd.ExcelWriter('/import_XLS/product_names_ean.xlsx', engine='xlsxwriter')  
df.to_excel(writer, index=False)
writer._save()