Witam,
funkcja zwraca None, ale kiedy printuję h, to normalnie wypisuje to, co ma printować.
#######################################
# EKAMEDICA
#######################################
from bs4 import BeautifulSoup as Bs
import xlrd
import urllib3
loc = ("data\\asortyment.xls")
wb = xlrd.open_workbook(loc)
sheet = wb.sheet_by_index(0)
http = urllib3.PoolManager()
#function returns existing products from ekamedica in the excel spreadsheet
def get_products():
prods = list()
counter = 0
for i in range(sheet.nrows):
if sheet.cell_value(i, 3) != 0:
if 'ekamedica' in sheet.cell_value(i,2).lower():
counter += 1
prods.append([sheet.cell_value(i,2).replace('EkaMedica ',''),sheet.cell_value(i,10),sheet.cell_value(i,13)])
return prods
#fuction gets html data of the product
#if there are more products than 1 matching the first word, search with one more word
def get_html(product, i):
p = '+'.join(product[0].split(' ')[0:i])
print(p)
url = 'https://ekamedica24.pl/szukaj?q=' + p
response = http.request("GET", url)
bs_data = Bs(response.data.decode('utf-8'), "html.parser")
if len(bs_data.find_all("div", {"class": "product-box"})) == 1:
h = bs_data.find("div", {"class": "product-box"})
print(h)#####TUTAJ JEST PROBLEM
return h
else:
if len(product[0].split(' ')) < i:
return None
get_html(product,i+1)
def main():
product = get_products()[0]
print(get_html(product,0))
if __name__ == '__main__':
main()
Z góry dzięki za pomoc.