我的代码需要一点帮助。我正在学习 Python 和美丽的汤,以便从戴尔网站上抓取一些数据。

我需要从特定服务器获取服务标签、保修和服务代码,但我不了解如何导航 HTML 树。

到目前为止,这是我的代码。

from selenium import webdriver
from selenium.,python,html,beautifulsoup"/>
	














首页 > 解决方案 > 如何使用 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

标签: pythonhtmlbeautifulsoup

解决方案


for sertag in soup.findAll('span', {'class': 'font-weight-medium text-jet'})[1]:
    print(sertag, sertag.next_element.strip())

推荐阅读