Issue
I need a little help with my code. I am learning Python and beautiful soup in order to scrape some data from the Dell website.
I need to get the service tag, warranty and service code from a particular server but I am not understanding how to navigate the HTML tree.
This is my code so far.
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()
The last "for" is where I can't figure out how to get the correct data.
for sertag in soup.findAll('p', {'class':'font-weight-medium text-jet'}):
print(sertag.text)
Basically, I would like to run the above block of code and get the below output.
Express Service Code: 14270045690
Can anyone help me with this? Can anyone also explain to me how to navigate in the right way in the HTML tree?
Solution
for sertag in soup.findAll('span', {'class': 'font-weight-medium text-jet'})[1]:
print(sertag, sertag.next_element.strip())
Answered By - αԋɱҽԃ αмєяιcαη
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.