i have problem with openpyxl. My code is working but i can not figure out for saving value to excel
my code is
JavaScript
x
14
14
1
def get_title(link):
2
global list2
3
driver = create_driver()
4
driver.get(link)
5
source = BeautifulSoup(driver.page_source, "lxml")
6
title = source.select_one("title").text
7
print(f"{link}: '{title}'")
8
9
for row in ws.rows:
10
if row[0].value == link:
11
print(row)
12
# ws.cell(row=???, column=2).value = title
13
# wb.save("site.xlsx")
14
and it prints out
JavaScript
1
5
1
https://www.google.com/search?q=2&oq=2&aqs=chrome..69i57j69i59l2j0i271l2j69i60l2j69i61.623j0j1&sourceid=chrome&ie=UTF-8: '2 - Google search'
2
(<Cell 'Sheet'.A2>, <Cell 'Sheet'.B2>)
3
https://www.google.com/search?q=6&oq=6&aqs=chrome..69i57j0i271l3j69i60l3.3687j0j1&sourceid=chrome&ie=UTF-8: '6 - Google search'
4
(<Cell 'Sheet'.A1>, <Cell 'Sheet'.B1>)
5
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
JavaScript
1
6
1
for row in ws.iter_rows(0):
2
for cell in row:
3
if cell.value == "test":
4
ws.cell(row=cell.row, column=2).value = "test"
5
wb.save("test.xlsx")
6
this one fix my problem