python - 如何使用 Beautifulsoup 获取文本
我的代码需要一点帮助。我正在学习 Python 和美丽的汤,以便从戴尔网站上抓取一些数据。
我需要从特定服务器获取服务标签、保修和服务代码,但我不了解如何导航 HTML 树。
到目前为止,这是我的代码。
from selenium import webdriver
from selenium.
问题描述
我的代码需要一点帮助。我正在学习 Python 和美丽的汤,以便从戴尔网站上抓取一些数据。
我需要从特定服务器获取服务标签、保修和服务代码,但我不了解如何导航 HTML 树。
到目前为止,这是我的代码。
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from bs4 import BeautifulSoup
import time
options = Options()
options.add_argument('--headless')
driver = webdriver.Firefox(options=options, executable_path=r'/Users/peterfranca/Downloads/geckodriver')
driver.get("https://www.dell.com/support/home/ca/en/cadhs1/product-support/servicetag/0-NE9lVXI4NlpmbjFtRHJBbTF0dDhoQT090/overview")
time.sleep(1)
soup = BeautifulSoup(driver.page_source, 'html.parser')
for model in soup.findAll('h1', {'class':'mb-3 mb-lg-1 text-center text-lg-left position-relative word-break'}):
print(model.text)
for tag in soup.findAll('p', {'class':'service-tag mb-0'}):
print(tag.text)
for warranty in soup.findAll('p', {'id':'warrantyExpiringLabel'}):
print(warranty.text)
for sertag in soup.findAll('p', {'class':'font-weight-medium text-jet'}):
print(sertag.text)
driver.quit()
最后一个“for”是我无法弄清楚如何获取正确数据的地方。
for sertag in soup.findAll('p', {'class':'font-weight-medium text-jet'}):
print(sertag.text)
基本上,我想运行上面的代码块并得到下面的输出。
Express Service Code: 14270045690
谁能帮我这个?谁能向我解释如何在 HTML 树中以正确的方式导航?
谐波振荡器
我正在尝试解决python中的简单摆。我的目标是将我的结果保存到一个文件中,以便之后进行绘图。我应该把保存数据的代码放在循环中还是定义一个新函数?
注意:我是初学者。
谢谢你。
import numpy as np
g = 9.8
L = 3
THETA_0 = np.pi / 4
THETA_DOT_0 = 0
def get_theta_double_dot(theta):
return - (g / L) * np.sin(theta)
def theta(t):
theta = THETA_0
theta_dot = THETA_DOT_0
dela_t = 0.01
for tps in np.arange(0, t, delta_t):
theta_double_dot = get_theta_double_dot(theta)
theta = theta + (theta_dot * delta_t)
theta_dot = theta_dot + (theta_double_dot * delta_t)
return theta
解决方案
for sertag in soup.findAll('span', {'class': 'font-weight-medium text-jet'})[1]:
print(sertag, sertag.next_element.strip())
推荐阅读
- ldap - OpenLDAP 搜索过滤器 DN 语法错误 (34) 身份验证失败
- python - 如何将所有 .txt 文件加载到具有不同名称的文件夹中 - Python
- electron - 我在哪里可以看到电子生成器自定义 NSIS 包含脚本中的回声输出?
- html - 使用 Golang 在特定打印机上打印 HTML
- reactjs - 内联使用情绪反应主题颜色
- javascript - 如何使用 formdata reactjs 发布图像数组
- http - 尽管 WriteHeader 用于返回另一个状态代码,但返回 200 状态代码
- ios - iOS SystemConfiguration plist - 更改HTTP代理不生效
- ios - 用画笔快速绘制
- html - Bootstrap 导航栏折叠没有折叠
我的代码需要一点帮助。我正在学习 Python 和美丽的汤,以便从戴尔网站上抓取一些数据。
我需要从特定服务器获取服务标签、保修和服务代码,但我不了解如何导航 HTML 树。
到目前为止,这是我的代码。
from selenium import webdriver
from selenium.
问题描述
我的代码需要一点帮助。我正在学习 Python 和美丽的汤,以便从戴尔网站上抓取一些数据。
我需要从特定服务器获取服务标签、保修和服务代码,但我不了解如何导航 HTML 树。
到目前为止,这是我的代码。
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from bs4 import BeautifulSoup
import time
options = Options()
options.add_argument('--headless')
driver = webdriver.Firefox(options=options, executable_path=r'/Users/peterfranca/Downloads/geckodriver')
driver.get("https://www.dell.com/support/home/ca/en/cadhs1/product-support/servicetag/0-NE9lVXI4NlpmbjFtRHJBbTF0dDhoQT090/overview")
time.sleep(1)
soup = BeautifulSoup(driver.page_source, 'html.parser')
for model in soup.findAll('h1', {'class':'mb-3 mb-lg-1 text-center text-lg-left position-relative word-break'}):
print(model.text)
for tag in soup.findAll('p', {'class':'service-tag mb-0'}):
print(tag.text)
for warranty in soup.findAll('p', {'id':'warrantyExpiringLabel'}):
print(warranty.text)
for sertag in soup.findAll('p', {'class':'font-weight-medium text-jet'}):
print(sertag.text)
driver.quit()
最后一个“for”是我无法弄清楚如何获取正确数据的地方。
for sertag in soup.findAll('p', {'class':'font-weight-medium text-jet'}):
print(sertag.text)
基本上,我想运行上面的代码块并得到下面的输出。
Express Service Code: 14270045690
谁能帮我这个?谁能向我解释如何在 HTML 树中以正确的方式导航?
我正在尝试解决python中的简单摆。我的目标是将我的结果保存到一个文件中,以便之后进行绘图。我应该把保存数据的代码放在循环中还是定义一个新函数?
注意:我是初学者。
谢谢你。
import numpy as np
g = 9.8
L = 3
THETA_0 = np.pi / 4
THETA_DOT_0 = 0
def get_theta_double_dot(theta):
return - (g / L) * np.sin(theta)
def theta(t):
theta = THETA_0
theta_dot = THETA_DOT_0
dela_t = 0.01
for tps in np.arange(0, t, delta_t):
theta_double_dot = get_theta_double_dot(theta)
theta = theta + (theta_dot * delta_t)
theta_dot = theta_dot + (theta_double_dot * delta_t)
return theta
for sertag in soup.findAll('span', {'class': 'font-weight-medium text-jet'})[1]:
print(sertag, sertag.next_element.strip())