Scubadivingfool Scubadivingfool - 1 year ago 82
Python Question

Combine two texts into one in Python

I am trying to scrape a website. I have got the information I need but I can't figure out how to output the prod title followed by a space and then the amount and then keep doing down until the end.

g_data = soup.find_all("h4", {"class": "prod-title"})
p_data = soup.find_all("span", {"class": "amount"})

for item in g_data:
print (item.text)
for item in p_data:
print (item.text)

print ("g_data" + "p_data")

Answer Source

Use zip().

for g, p in zip(g_data, p_data):
    print(g.text, p.text)