-4

I just want to search the company name on the search button, type the company name and then it will open the link of that company if exist I tried a lot of ways and there are always problems. .new to web scraping

I have tried:

from selenium import webdriver

driver=webdriver.Chrome("C:/Users/RoshanB/Desktop/sentiment1/chromedriver_win32/chromedriver")

driver.get("http://www.careratings.com/brief-rationale.aspx")

but now I don't know how to click on "Search company name", type company name and open that company link using selenium

Darshan Jain
  • 781
  • 9
  • 19
Roshan
  • 1
  • 5

2 Answers2

0

This should work for you, I have tried with id locator :

driver.maximize_window()

driver.get("http://www.careratings.com/brief-rationale.aspx")


search_company = driver.find_element_by_id("txtSearchCompany_brief")
search_company.send_keys("Abc India Limited:")

submit_button = driver.find_element_by_id("btn_submit").click()
submit_button.click()  

Though, you would have to write the code if company name is not available.

cruisepandey
  • 28,520
  • 6
  • 20
  • 38
  • How to click on the date range of last two days, give date range like from (2019-05-17 to 2019-05-19) than search company name from a list (like Ramdhan Spintex,Axis bank limited) if it exist than it will open the link search,open pdf and extract the rating1 and rating action and update into my own excel from selenium import webdriver driver=webdriver.Chrome("C:/Users/RoshanB/Desktop/sentiment1/chromedriver_win32/chromedriver") driver.get("http://www.careratings.com/brief-rationale.aspx") using the above link – Roshan May 20 '19 at 08:54
  • @Roshan : Try something, if things don't work out for you then ask. We can't write whole script to you. It's just unfair to us. – cruisepandey May 20 '19 at 09:24
  • driver=webdriver.Chrome("C:/User/chromedriver_win32/chromedriver") driver.get('http://www.careratings.com/brief-rationale.aspx') companyArray = [] search=driver.find_element_by_id('txtfromdate') search.send_keys("2019-05-17") search1=driver.find_element_by_id('txttodate') search1.send_keys("2019-05-20") submit_button=driver.find_element_by_id("btn_submit").click() soup = BeautifulSoup(driver.page_source, 'lxml') companies =soup.find("table",class_="table1") for tag in companies.findChildren(): if isinstance(tag, Tag) and tag.name in 'a': print(tag.text) – Roshan May 20 '19 at 11:23
  • can somebody please help in this – Roshan May 21 '19 at 08:53
0

Try this:

from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
from bs4.element import Tag

driver = webdriver.Chrome("C:/Users/RoshanB/Desktop/sentiment1/chromedriver_win32/chromedriver")
driver.get('http://www.careratings.com/brief-rationale.aspx')
time.sleep(4)

companyArray = []

try:
    search = driver.find_element_by_name('txtSearchCompany_brief')
    search.send_keys("Reliance Capital Limited")
    search.send_keys(Keys.RETURN)
    time.sleep(4)
    soup = BeautifulSoup(driver.page_source, 'lxml')
    companies = soup.find("table",class_="table1")

    for tag in companies.findChildren():
        if isinstance(tag, Tag) and tag.name in 'a' and tag.has_attr('href'):
            url_string = "http://www.careratings.com/"+tag['href'].replace (" ","%20")
""" **Open pdf file in new tab browser** """
            open_pdf(url_string)
            companyArray.append(tag.text)

except Exception as e:
    print(e)

driver.quit()
print(companyArray)

O/P

Company list:

['Reliance Capital Limited', 'Dewan Housing Finance Corporation Limited Ratings of various Securitisation transactions', 'Gamut Infosystems Limited', 'Henraajh Feeds India Private Limited', 'Ramdhan Spintex', 'Tripurashwari Agro Product Private Limited', 'Kalyaneswari Polyfabs Private Limited', 'Rakesh Kumar Gupta Rice Mills Private Limited', 'Sri Satnam Jewells Private Limited', 'Pitambara Foods', 'Sujata Udit Builders Private Limited', 'Kavita Industries', 'Krishna Industries', 'Pallavi Motors Private Limited', 'Anjani Cotgin', 'Sarala Foods Private Limited', 'B.M. Enterprises', 'Bihani Agro Foods Private Limited', 'M V Agrotech Private Limited', 'J.S.R & Company', 'ARG Royal Ensign Developers Private Limited', 'Ranergy Solutions Private Limited', 'RSI Switchgear Private Limited', 'Jyoti Chandrashekhar Bawankule', 'Sadguru Engineers & Allied Services Private Limited', 'R B Rungta Steels & Food Products Private Limited', 'V. N. Marketing', 'Aussee Oats India Limited', 'Dewan Housing Finance Corporation Limited', 'Dewan Housing Finance Corporation Limited', 'Dewan Housing Finance Corporation Limited', 'Dewan Housing Finance Corporation Limited', 'Dewan Housing Finance Corporation Limited', 'Dewan Housing Finance Corporation Limited', 'Dewan Housing Finance Corporation Limited', 'Dewan Housing Finance Corporation Limited', 'Dewan Housing Finance Corporation Limited', 'Dewan Housing Finance Corporation Limited', 'Dewan Housing Finance Corporation Limited', 'Dewan Housing Finance Corporation Limited', 'Dewan Housing Finance Corporation Limited', 'Pacific Medical University', 'S. K. Pradhan Construction Company Private Limited', 'Stadmed Private Limited', 'Namra Finance Limited', 'S Kumars Associates', 'R. R. and Company Private Limited']

if you want to scrape company name, need to install BeautifulSoup package

pip install beautifulsoup4==4.7.1

Where:

txtSearchCompany_brief is input search name

table1 is search results table class

Download pdf file link:

Chromedriver, Selenium - Automate downloads

Read pdf file link:

How to read line by line in pdf file using PyPdf?

Open pdf file in a new tab:

def open_pdf(url_string):
    driver1 = webdriver.Chrome("C:/Users/RoshanB/Desktop/sentiment1/chromedriver_win32/chromedriver")
    driver1.get(url_string)
bharatk
  • 4,202
  • 5
  • 16
  • 30
  • How to open the pdf of company name after submit button? – Roshan May 20 '19 at 09:26
  • i want to give date range also beacuse it open the pdf of 2017 search1=driver.find_element_by_id('txtfromdate') search1.send_keys("2019-05-17") search2=driver.find_element_by_id('txttodate') search2.send_keys("2019-05-20") search=driver.find_element_by_name('txtSearchCompany_brief') search.send_keys("Reliance Capital Limited") search.send_keys(Keys.RETURN) time.sleep(4) but in this it shows error...can you please check how to give date range also – Roshan May 21 '19 at 05:33
  • and one more thing in your code everytime it opens the pdf link of only one company i.e "Reliance Capital Limited" – Roshan May 21 '19 at 08:52
  • @Roshan I updated the answer for last comment, open pdf file in new tab. – bharatk May 21 '19 at 10:24
  • @Roshan try your self to resolve date range issue because we are here to resolve small code or syntax error related issue, not for writing a full script. – bharatk May 21 '19 at 10:28
  • okay Bharat I will update my solution also with the date range here – Roshan May 21 '19 at 17:37
  • hey@bharat the pdf of the company is different from the search company – Roshan Jun 02 '19 at 06:57