【发布时间】:2022-01-18 22:11:29
【问题描述】:
我对 openpyxl 有疑问。我的代码正在运行,但我不知道如何将价值保存到 excel
我的代码是
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 列,但我不知道该怎么做
【问题讨论】:
-
这有点老了,但它应该能让你在使用 pandas 库的帮助下取得进步:stackoverflow.com/questions/49681392/…
-
谢谢,但它对我不起作用,我需要在 excel 中匹配 url 和标题。如果我转向熊猫,我需要更改许多代码
-
不仅仅是
row[1].value = title?
标签: python python-3.x excel openpyxl