Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Web scrapping - Stopped working
#3
Thanks mlieqo for your help
I tried your suggestion and it worked sometimes but not consistent.

I tried to do this in a loop with multiple stock symbols as below. Now I get a different error that "You are not authorized to access...". More over it does the loop once and for the second stock in the list, the target server is refusing connection even to https://www.nseindia.com/option-chain

I guess they are trying to prevent people from scrapping this site? Is my understanding correct, or am I doing something wrong?

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from bs4 import BeautifulSoup
import time

options = Options()
browser = webdriver.Chrome(executable_path=r"C:\Users\Admin\Downloads\chromedriver_win32\chromedriver.exe",options=options)
stocklist = ['ACC','HDFC','HCLTECH','ICICIBANK','RELIANCE','SBIN',] 

for symbl in stocklist:    
    url = "https://www.nseindia.com/api/option-chain-equities?symbol={stck}".format(stck=symbl)
    
    print('Trying nse option chain')
    browser.get('https://www.nseindia.com/option-chain')
    time.sleep(3)
    print('Symbol - {stck}'.format(stck=symbl))
    print('Trying api url')
    browser.get(url)   
    time.sleep(3)
    #soup = BeautifulSoup(browser.page_source,'lxml')
    browser.quit()
Reply


Messages In This Thread
Web scrapping - Stopped working - by peterjv26 - Sep-22-2020, 02:09 PM
RE: Web scrapping - Stopped working - by mlieqo - Sep-22-2020, 07:51 PM
RE: Web scrapping - Stopped working - by peterjv26 - Sep-23-2020, 08:30 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with scrapping Website giddyhead 1 1,657 Mar-08-2024, 08:20 AM
Last Post: AhanaSharma
  python web scrapping mg24 1 375 Mar-01-2024, 09:48 PM
Last Post: snippsat
  How can I ignore empty fields when scrapping never5000 0 1,415 Feb-11-2022, 09:19 AM
Last Post: never5000
  Suggestion request for scrapping html table Vkkindia 3 2,081 Dec-06-2021, 06:09 PM
Last Post: Larz60+
  web scrapping through Python Naheed 2 2,654 May-17-2021, 12:02 PM
Last Post: Naheed
  Website scrapping and download santoshrane 3 4,394 Apr-14-2021, 07:22 AM
Last Post: kashcode
  Image Scraper (beautifulsoup), stopped working, need to help see why woodmister 9 4,119 Jan-12-2021, 04:10 PM
Last Post: woodmister
  Newbie help with lxml scrapping chelsealoa 1 1,884 Jan-08-2021, 09:14 AM
Last Post: Larz60+
  Scrapping Sport score laplacea 1 2,298 Dec-13-2020, 04:09 PM
Last Post: Larz60+
  How to export to csv the output of every iteration when scrapping with a loop efthymios 2 2,332 Nov-30-2020, 07:46 PM
Last Post: efthymios

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020