i have problem with openpyxl. My code is working but i can not figure out for saving value to excel
my code is
def get_title(link):
global list2
driver = create_driver()
driver.get(link)
source = BeautifulSoup(driver.page_source, "lxml")
title = source.select_one("title").text
print(f"{link}: '{title}'")
for row in ws.rows:
if row[0].value == link:
print(row)
# ws.cell(row=???, column=2).value = title
# wb.save("site.xlsx")
and it prints out
https://www.google.com/search?q=2&oq=2&aqs=chrome..69i57j69i59l2j0i271l2j69i60l2j69i61.623j0j1&sourceid=chrome&ie=UTF-8: '2 - Google search' (<Cell 'Sheet'.A2>, <Cell 'Sheet'.B2>) https://www.google.com/search?q=6&oq=6&aqs=chrome..69i57j0i271l3j69i60l3.3687j0j1&sourceid=chrome&ie=UTF-8: '6 - Google search' (<Cell 'Sheet'.A1>, <Cell 'Sheet'.B1>)
what i want to do is i want to save title to B column in excel but i don’t know how to do that
Advertisement
Answer
for row in ws.iter_rows(0):
for cell in row:
if cell.value == "test":
ws.cell(row=cell.row, column=2).value = "test"
wb.save("test.xlsx")
this one fix my problem