I assume you always just want what's between the slashes next to dp (the next route), and that the 10 characters is kind of irrelevant. A little clunky, but this works:
>>> x = '<a class="a-link-normal" href="https://www.amazon.it/Philips-GC8735-PerfectCare-Generatore-Vapore/dp/B01J5FGW66/ref=gbph_img_s-3_7347_c3de3e94?smid=A11IL2PNWYJU7H&pf_rd_p=82ae57d3-a26a-4d56-b221-3155eb797347&pf_rd_s=slot-3&pf_rd_t=701&pf_rd_i=gb_main&pf_rd_m=A11IL2PNWYJU7H&pf_rd_r=MDQJBKEMGBX38XMPSHXB" id="dealImage"></a>'
>>> splits = x.split("/")
>>> dp_index = splits.index('dp')
>>> result = splits[dp_index+1] # Get the next one over
>>> result
'B01J5FGW66'
to put it in a funciton, you can do it like this:
def get_route_next_to_dp(html_str):
splits = html_str.split("/")
dp_index = splits.index('dp')
result = splits[dp_index+1] # Get the next one over
return result
Usage might look like:
html_str = '<a class="a-link-normal" href="https://www.amazon.it/Philips-GC8735-PerfectCare-Generatore-Vapore/dp/B01J5FGW66/ref=gbph_img_s-3_7347_c3de3e94?smid=A11IL2PNWYJU7H&pf_rd_p=82ae57d3-a26a-4d56-b221-3155eb797347&pf_rd_s=slot-3&pf_rd_t=701&pf_rd_i=gb_main&pf_rd_m=A11IL2PNWYJU7H&pf_rd_r=MDQJBKEMGBX38XMPSHXB" id="dealImage"></a>'
route_next_to_dp = get_route_next_to_dp(html_str)
print(route_next_to_dp)
outputs
'B01J5FGW66'
as desired.