Tag: scraping openpyxl

循环项目并保存到.xlsx文件,只保存最后一个值使用网页抓取?

我对Python很新。 尽量在做项目的同时尽量学习,以保持兴趣水平。 在下面的代码中,我试图从网站上获取信息,并将所有的公司名称和地址等存入excel文件。 我想我需要定义如何为每个迭代/公司分配excel行和列。 我只是对如何去做一个空白。 import requests, os from bs4 import BeautifulSoup from openpyxl import Workbook from openpyxl import load_workbook url = "https://dir.indiamart.com/search.mp?ss=Power+Distribution+Transformers" r = requests.get(url) soup = BeautifulSoup(r.content) links = soup.find_all("a") for link in links: print("<a href='%s'>%s</a>" % (link.get("href"), link.text)) g_data = soup.find_all("div", {"class": "nes"}) c = [] d = [] for item in […]