Python Forum
Follow Up: Web Calendar based Extraction
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Follow Up: Web Calendar based Extraction
#1
Hey, I am not a programmer but thanks to this forum, I have been learning a lot. Continuing on with my last time question to this link:
https://python-forum.io/Thread-Extractin...m-Calendar
I did learn to use selenium, however I do not understand on now how to extract data from each pages separately. The code that I have written (not by me but mostly by the help of @Snippsat) doesn't seem to work.
Any help on how to extract data from specific web pages after getting it done through a calendar.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
import time   
import requests

browser = webdriver.Chrome()

def stock_data(date):
    url = 'https://www.sharesansar.com/today-share-price'
    browser.get(url)
    inputElement = browser.find_element_by_id('fromdate')
    inputElement.clear()
    inputElement.send_keys(date)
    inputElement.send_keys(Keys.RETURN)
    #time.sleep(5) #seconds
    inputElement=browser.find_element_by_id('btn_todayshareprice_submit')
    inputElement.click()
    response = requests.get('https://www.sharesansar.com/ajaxtodayshareprice')
    return response

def parse_data(response, date):
    soup = BeautifulSoup(response.content, 'lxml')
    print(f'-----| {date} |-----')
    companyname=soup.select('td:nth-child(7)')
    for i in companyname:
        try:
            CP=i.text
            print('Closing Price:',CP)
        except:
            AttributeError
if __name__ == '__main__':
    for day in range(17,22):
        date = f'2020-02-{day}'
        response = stock_data(date)
        parse_data(response, date)
Output:
DevTools listening on ws://127.0.0.1:50193/devtools/browser/1696afe4-6409-4739-a193-e19e18808298 -----| 2020-02-17 |----- -----| 2020-02-18 |----- -----| 2020-02-19 |----- -----| 2020-02-20 |----- -----| 2020-02-21 |-----
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Online calendar for booking. SpongeB0B 6 3,469 Nov-15-2023, 11:27 AM
Last Post: Woki
  Python Scrapy Date Extraction Issue tr8585 1 3,295 Aug-05-2020, 04:32 AM
Last Post: tr8585
  Article Extraction - Wordpress svzekio 7 5,272 Jul-10-2020, 10:18 PM
Last Post: steve_shambles
  Extracting Data from Calendar AgileAVS 2 3,719 Feb-16-2020, 01:06 PM
Last Post: AgileAVS
  fb data extraction error periraviteja 1 2,154 Jan-05-2019, 01:07 AM
Last Post: stullis
  Email extraction from websites stefanoste78 14 12,080 Aug-18-2017, 09:44 PM
Last Post: stefanoste78
  Requisites for live data extraction and display Denniz 1 3,028 May-03-2017, 08:54 PM
Last Post: nilamo
  Google Calendar iCal Albireo 2 5,490 Mar-15-2017, 03:47 PM
Last Post: Albireo
  [SOLVED] requests returning HTTP 404 when I follow a link after I do a POST JChris 9 27,836 Nov-14-2016, 02:23 PM
Last Post: JChris

Forum Jump:

User Panel Messages

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