problema con un script: skipped 'NoneType' object is not suscriptable
Publicado por javier (2 intervenciones) el 08/06/2019 21:30:21
Hola a todos,
Estoy trasteando un script para una página web. Extrae datos tales como precio, valoración, foto...
El problema es que la web ha cambiado y me devuelve por linea de comandos un error que antes no daba. Debe ser por la nueva interfaz
Yo mando este enlace: http://s.click.aliexpress.com/e/b4dj7tZA
Mi código es el siguiente:
Y me devuelve el error: skipped 'NoneType' object is not suscriptable
antes, con la versión anterior de la web, funcionaba.
¿que puede estar fallando?
Gracias,
Saludos.
Estoy trasteando un script para una página web. Extrae datos tales como precio, valoración, foto...
El problema es que la web ha cambiado y me devuelve por linea de comandos un error que antes no daba. Debe ser por la nueva interfaz
Yo mando este enlace: http://s.click.aliexpress.com/e/b4dj7tZA
Mi código es el siguiente:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import re
from requests_html import HTMLSession
def start(url): #Takes info of a product, including url of product page and scrapes Price,rating and others
timeout = 1
session = HTMLSession()
header = {'User-agent': 'Mozilla/5.0', 'aep_usuc_f':'site=glo&province=919986676578000000&city=919986676578011000&c_tp=EUR®ion=ES&b_locale=en_US'}
cookies = {'aep_usuc_f':'site=glo&province=919986676578000000&city=919986676578011000&c_tp=EUR®ion=ES&b_locale=en_US'}
r = session.get(url, headers=header, cookies=cookies) #Open URL of the product
price = getprice(r) #Gets the price of the product
while price is None and timeout < 5: #Retries 5 times in case the proxy isn't working
r = session.get(url, headers=header)
print(r.status_code)
price = getprice(r)
timeout += 1
price.replace(',','') #Remove commas
discountlist = getdiscount(r) #Get if there is a discount
discount = discountlist[0]
oldprice = discountlist[1]
oldprice = oldprice.replace(',','')
oldprice =re.sub(r'[^-^\d^\.]+', '', oldprice)
rating = getrating(r)
title = gettitle(r).replace(',',' ') #
photo = r.html.search('<img alt={} src="{}" data-role="thumb" style="max-width: 500px; max-height: 500px;"')[1]
return { #Return the info of the product to be stored/displayed
'price':price,
'discount':discount,
'oldprice':float(oldprice),
'title':title,
'rating':rating,
"photo":photo
}
def getprice(r): #Get the price of the product from its url
price = r.html.search('<span itemprop="lowPrice">{}</span> - <span itemprop="highPrice">{}</span>')
if price is not None:
price = price[0]+"€" # + "-€"+ price[1]
return price
else:
price = r.html.search('"actSkuMultiCurrencyCalPrice":"{}","')
price = price[0] + "€"
return price
def getdiscount(r): #Get the discount of the product from its url, and the old price if there is a discount
oldprice = r.html.search('<span class="a-text-strike"> {}</span>')
if oldprice is not None:
return [True, oldprice[0]]
else:
return [False, '-1']
def getrating(r):
rating = r.html.search('<span class="percent-num">{}<')
no = r.html.search('<span class="rantings-num">({} votes')
if rating is not None:
rat = rating[0]
if (".0" in rat):
rat = rat.strip(".0")
return (rat + " / 5 (" + no[0] +" opiniones)")
def gettitle(r): #Get the title of the product from its url
title = r.html.search('<title>{}</title>')
if (title is not None):
print(title[0].strip().strip("Aliexpress.com : "))
return (title[0].strip().strip("Aliexpress.com : ").strip('" />'))
else:
title = r.html.search('<meta property="og:title" content="{}|{}" />')
return (title[1].strip().strip("Aliexpress.com : ").strip('" />'))
Y me devuelve el error: skipped 'NoneType' object is not suscriptable
antes, con la versión anterior de la web, funcionaba.
¿que puede estar fallando?
Gracias,
Saludos.
Valora esta pregunta


1