- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
任何人都可以请帮助初学者。我编写了一些代码来收集网站的所有公司名称。它还打印出所有这些。但是,当我尝试将数据输入到 Excel 文件中时,它只输入最后的公司名称。
继承人的代码:如果有人可以帮助我会很感激它。
import requests
from bs4 import BeautifulSoup
from openpyxl import Workbook
print('Welcome!')
search = input('Search for what? ')
URL = 'https://www.merinfo.se/search?ap=1&emp=0%3A100&rev=0%3A100000&d=c&who=' + search + '&where=&bf=1'
headers = {
'User Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15'
}
page = requests.get(URL, headers=headers)
soup = BeautifulSoup(page.content, 'html.parser')
for i in soup.find_all('h2', class_='name'):
print(i.get_text())
workbook = Workbook()
sheet = workbook.active
sheet["A2"] = i.get_text()
workbook.save(filename="foretagen.xlsx")
最佳答案
您可以使用 sheet.append()
将行添加到 excel 文件。
例如:
import requests
from bs4 import BeautifulSoup
from openpyxl import Workbook
print('Welcome!')
search = input('Search for what? ')
URL = 'https://www.merinfo.se/search?ap=1&emp=0%3A100&rev=0%3A100000&d=c&who=' + search + '&where=&bf=1'
headers = {'User Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15'}
page = requests.get(URL, headers=headers)
soup = BeautifulSoup(page.content, 'html.parser')
workbook = Workbook()
sheet = workbook.active
for i in soup.find_all('h2', class_='name'):
txt = i.get_text(strip=True)
print(txt)
sheet.append([txt])
workbook.save(filename="foretagen.xlsx")
打印:
Welcome!
Search for what? tree
Tree Logistics AB
Sushi tree AB
Beech Tree AB
BIN TREE AB
TALENT TREE AB
Juniper Tree AB
Hope Tree AB
Dead tree group AB
The Tree Karsikko AB
Willow Tree Consulting AB
Learning Tree International Aktiebolag
Palm Tree Tunes AB
Tree of Pets AB
nordic tree care AB
For Tree i Rossön Aktiebolag
Trädkompaniet Voice Of Tree Care AB
Omsorgshuset Red Tree Care Center AB
Global Tree Care i Sundbyberg AB
Three Rock AB
Three Gates AB
并写入 excel 文件(来自 LibreOffice 的屏幕截图):
关于python - BS4 收集要列出的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62852479/
我正在尝试运行基于 angular2 的第一个应用程序。我关注了angular2脚步。当我运行命令 npm start 然后它在终端中给出以下错误 Did not detect a bs-config
×
我在 stackovefflow 上搜索并没有找到这个问题的答案。我是 Angular 2 的新手,我正在创建一个演示应用程序,但是当我执行 npm start 时,此消息显示在终端/控制台上。虽然它
如果 .popover() 之后变成 .on('hidden.bs.popover'),我想'销毁'是 .on('shown.bs.popover' 所以它不会再 'show' 。一切似乎都正确,但看
我在玩 vimgolf challenge 时遇到了以下问题: :%s/V/i?/giiZZ 我认为意思是“退格键”,但是当我在键盘的命令行模式下按退格键时,它只是删除了“?” (我正在使用带有 Mi
我正在制作一个 BS 轮播。当浏览器较小且文本未居中时,图像看起来不合适并且不会完全覆盖轮播。我该如何解决这个问题?我还没有找到可以帮助我的答案。 这是我的 CSS: .carousel-inn
在优势网格中,当单击另一个分区时,一个分区的卡体会折叠。然而,另一个网格并没有发生同样的情况(缺点)。当我们单击劣势部分的一个分区时,当我们再次单击劣势部分的另一个分区时,它不会被折叠。然而,这是在优
在下面的代码中,我正在学习如何创建 2 列,并将左列用作可滚动的导航栏。我这里还处于零阶段,所以请原谅质量! 我在将 .sidebar 类设置为左栏中的 "position:fixed" 时遇到了问题
我尝试使用 javascript 动态 + bs + python 进行网页抓取,并且我阅读了很多内容来编写此代码,例如,我尝试在著名网站上抓取使用 javascript 呈现的价格: from bs
我想在右侧的标题中添加一个额外的小元素,该元素与右侧对齐,如下所示: Headersubheadersubheader right 但是右侧的 span 元素放置得更高/与第一个小元素不在一条直线上。
我正在使用 BS3 并且有这样的选项卡: Annual Summary Monthly Summary 我在第一个选项卡中有一个像这样的链接:
有谁知道如何在使用 css 打开或关闭时更改 bootstrap 4 navbar-toggler-icon?我认为这很简单,但我真的找不到任何东西。 .map-controls-mobile .na
大家好……我想从网页上的表格中选择一个关于特定位置的词。源代码如下: table = ''' Code: BAN Color: White ''
我正在尝试使用现有代码库配置 gcov 以实现代码覆盖。现有代码base 是基于服务的代码库(即包含多个文件 c 和 cpp 以及一项服务) 我已经关注了配置 gcov 的 wiki 页面并添加了 -
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 8 年前。 Improve t
我在 FlashBuilder 中开发了一个浏览器部署的全文搜索应用程序,该应用程序以 REST 方式与远程 Web 服务器进行通信。该软件适合一个小众市场——它适用于古代语言而不是现代语言,我不可能
我正在尝试使用 Angular 带的 Bootstrap 工具提示编写简单的代码。我发现使用 bs-tooltip 时 AngularJs 数据绑定(bind)不起作用。 绑定(bind)不起作用
我使用 bootstrap modal + slick slider 在 bs modal 窗口中显示 slider ,但在显示时遇到一些问题。自动播放之前 slider 未打开 not work 但
我正在尝试从引导下拉列表中捕获事件。似乎什么都不起作用,尽管显然我做错了什么。 代码,精简为问题...... Dem
为什么 loaded.bs.modal 事件从 Bootstrap 4 中删除?有什么东西可以代替它吗? shown.bs.modal 非常相似,但它不会等待模态完全加载,而只是显示。 最佳答案 基本
我是一名优秀的程序员,十分优秀!