#๐Ÿ”’ Issue with web scraping using selenium

27 messages ยท Page 1 of 1 (latest)

coarse quarry
#
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from bs4 import BeautifulSoup
import time 
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

chrome_options = Options()
chrome_options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36")

# Path to your ChromeDriver executable
driver_path = 'C:/AFM P1/chromedriver-win64 (2)/chromedriver-win64/chromedriver.exe'

# Initialize the ChromeDriver Service
service = Service(driver_path)

# Initialize the Chrome WebDriver using the Service object
driver = webdriver.Chrome(service=service, options=chrome_options)

# Open the NSE page
url = "https://www.nseindia.com/get-quotes/equity?symbol=ADANIENT"
driver.get(url)

#Wait for the dynamic data to load
#try:
 #   WebDriverWait(driver, 20).until(
  #    EC.presence_of_element_located((By.ID, 'securities_info_table'))  # Wait until the table is located
   # )
    #print("Table loaded.")
#except:
 #  print("Page or element not fully loaded")

# Get the page source after the delay
html = driver.page_source

# Use BeautifulSoup to parse the dynamically loaded HTML
soup = BeautifulSoup(html, 'html.parser')

# Find the 'SectoralIndxPE' element and the next <td> that contains the Adjusted P/E value
adjusted_pe_label = soup.find('td', id='SectoralIndxPE')
if adjusted_pe_label:
    # Get the next sibling <td> which contains the value
    adjusted_pe_value = adjusted_pe_label.find_next('td').text.strip()
    print(f"Adjusted P/E: {adjusted_pe_value}")
else:
    print("Adjusted P/E not found")

# Close the browser when done
driver.quit()
leaden capeBOT
#

@coarse quarry

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

coarse quarry
#

Hi

#

I am trying to get adjusted pe

#

from nse website

#

but i am getting none output

#

also the website is not getting loaded fully

#

what to do

#

THis is what only getting loaded

#

and no content

#

adjusted pe is located in securities info table

#

anyone any idea

tiny wasp
#

!rule 5

leaden capeBOT
#

5. Do not provide or request help on projects that may violate terms of service, or that may be deemed inappropriate, malicious, or illegal.

tiny wasp
#
  1. You should not conduct any systematic or automated data collection activities (including scraping, data mining, data extraction and data harvesting) on or in relation to our website.
coarse quarry
#

oh ok

#

sorry

#

was not ware

#

what i do now

tiny wasp
tiny wasp
coarse quarry
#

Okay.

#

!close

leaden capeBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.