I have such result:
{'name': name1 , 'pic': pic1}
{'name': name1 , 'pic': pic2}
{'name': name1 , 'pic': pic3}
{'name': name2 , 'pic': pic4}
{'name': name2 , 'pic': pic5}
{'name': name2 , 'pic': pic6}
{'name': name3 , 'pic': pic7}
{'name': name3 , 'pic': pic8}
{'name': name3 , 'pic': pic9}
{'name': name3 , 'pic': pic10}
And I need this:
{'name': name1 , 'pic': pic1, pic2, pic3}
{'name': name2 , 'pic': pic4, pic5, pic6}
{'name': name3 , 'pic': pic7, pic8, pic9, pic10}
How can I do that?
My code is:
for links in url_list:
try:
r = requests.get(links, headers=headers, params=params, timeout=20)
except requests.exceptions.ConnectionError as err:
print('Bad status code', r.status_code)
soup = BeautifulSoup(r.content, 'lxml')
name = soup.find('h1', class_='name')
pics = soup.findAll('a', class_='gallery')
for pic in pics:
pic = baseurl + pic['href']
list = {'name': name,'pic': pic}
print(list)
Here is one way to do it:
Assuming you have your original dictionaries in a list
pic_list
:You could :
name
,Here is the code:
OUTPUT: