如何将<单元格'工作表'.A2>变成只有 2?



我对openpyxl有问题。我的代码正在工作,但我不知道如何节省价值来超越

我的代码是

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")

它打印出

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>)

我想做的是,我想把标题保存到excel中的B列,但我不知道如何做

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")

这个解决了我的问题

最新更新