how can i get the text from tspan tag by using pythonl beatiful soup with xpath

130 views Asked by At
from bs4 import BeautifulSoup
from lxml import etree
import requests
from lxml import html

url="https://www.findchips.com/detail/TS63Y502KR10/2516-Vishay%20Intertechnologies?quantity=1"
Dict_Headers = ({'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36'})

webPage = requests.get(url,Dict_Headers)

Scraping = BeautifulSoup(webPage.content, "html.parser") 

documentObjectModel = etree.HTML(str(Scraping)) 


Distri_Name=documentObjectModel.xpath('//span[@class="distri-name"]')
Inventory_Number=documentObjectModel.xpath('//span[@class="inventory-number"]')

Infor_Number=documentObjectModel.xpath('//tspan[@class="point-info-number large"]')
print(len(Infor_Number))

print(len(Infor_Number)) # returns 0 means i got nothing returned from the finding. #i need to get the text on this tspan , which is $3.7200 #please help??

1

There are 1 answers

0
lee On
*problem solved by myself today! the following is the code*

from selenium import webdriver
import time
import requests
from bs4 import BeautifulSoup
from selenium.webdriver.common import by
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

import re


from selenium.webdriver.chrome.options import Options


s=Service(ChromeDriverManager().install())
#options = Options()
#options.add_argument('headless')
# then pass options to the driver
#driver=webdriver.Chrome(executable_path="C:\\Users\\Purchasing\\pythontest\chromedriver_win32\\chromedriver.exe")
#driver = webdriver.Chrome(service=s, options=options) 

driver = webdriver.Chrome(service=s)
driver.maximize_window()
driver.get('https://www.findchips.com/detail/TS63Y502KR10/2516-Vishay%20Intertechnologies?quantity=10')#('https://codeforces.com/profile/akash77')
elements = driver.find_elements(By.XPATH, '//*[@class="j-analytics-pricing-graph pricing-graph"]')
print(len(elements))
svg = [WebElement.get_attribute('innerHTML') for WebElement in elements]
Great_Price_less=str(svg).split("point-info-number large")[-1].split("point-info-text large")[-2].split("<")[-3].split(">")[-1]
Great_Price_more=str(svg).split("point-info-number large")[-2].split("point-info-text large")[-2].split("<")[-3].split(">")[-1]

print(Great_Price_more + " " + Great_Price_less)

driver.quit()