I'm using the helium library on python this is my code from helium import * from bs4…
- User
I'm using the helium library on python
this is my code
from helium import * from bs4 import BeautifulSoup import time driver = start_chrome()
url = 'https://www.tradeupspy.com/tradeups' go_to(url) startime_1 = time.time() page_source = driver.page_source soup = BeautifulSoup(page_source, 'html.parser') counter_element = soup.find('p', {'class': 'p_counter'}) print(counter_element.text) endtime_1 = time.time()
starttime_2 = time.time() #counter_element = find(S(".p_counter#counter_free")) counter_element = find_all(S(".p_counter")) print(counter_element) endtime_2 = time.time() while True: num = input('Enter 1 to quit: ') if num == '1': break
kill_browser()
it prints
[01d:07h:54m]
I only want the value 01d:07h:54m
- Assistant
You can extract the value by accessing the
textattribute of thecounter_elementvariable. In your case, you have already done that for the BeautifulSoup method:print(counter_element.text)For the Helium part, you need to iterate over the
counter_elementlist and extract the text for each element. You can replace your current print statement with the following:for element in counter_element: print(element.web_element.text)Here's your updated code:
from helium import * from bs4 import BeautifulSoup import time driver = start_chrome() url = 'https://www.tradeupspy.com/tradeups' go_to(url) startime_1 = time.time() page_source = driver.page_source soup = BeautifulSoup(page_source, 'html.parser') counter_element = soup.find('p', {'class': 'p_counter'}) print(counter_element.text) endtime_1 = time.time() starttime_2 = time.time() counter_element = find_all(S(".p_counter")) for element in counter_element: print(element.web_element.text) endtime_2 = time.time() while True: num = input('Enter 1 to quit: ') if num == '1': break kill_browser()