I'm getting data in two different for loops with BeautifulSoup, but I couldn't find how to combine data from these two different loops in excel.
file = open('/path/test.csv', "a", encoding= "utf-8", newline='')
writer = csv.writer(file)
writer.writerow(["Phone Number","Firm Name"])
response = requests.get(url)
soup = BeautifulSoup(response.content, "lxml")
phones = soup.findAll("div", attrs={"class":"PhonesBox"})
names = soup.findAll("h2", attrs={"class":"CompanyName"})
try:
for phone in phones:
firm_phone = phone.find("label").text
writer.writerow([firm_phone])
for name in names:
firm_name = name.find("span").text
writer.writerow([firm_name])
except:
pass
If I use it like this, of course I get the results one after the other, but what I need is ([firm_phone,firm_name]) in excel file. Any help appreciated.