Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.IO;
- using System.Linq;
- using System.Data;
- using OfficeOpenXml;
- using System.Collections.Generic;
- using System;
- using OpenQA.Selenium;
- using OpenQA.Selenium.Firefox;
- namespace ConsoleApplication1
- {
- public class Program
- {
- public static void Main()
- {
- var profile = new FirefoxProfile();
- profile.AcceptUntrustedCertificates = true;
- var browser = new FirefoxDriver(profile);
- // Click the spell buton only one time
- browser.Navigate().GoToUrl("http://dictionary.reference.com/browse/start");
- var spellButton = browser.FindElementByClassName("pronounce-Spell-button");
- spellButton.Click();
- var existingFile = new FileInfo("Dictionary.xlsx");
- // Open and read the XlSX file.
- using (var package = new ExcelPackage(existingFile))
- {
- // Get the work book in the file
- ExcelWorkbook workBook = package.Workbook;
- if (workBook.Worksheets.Count > 0)
- {
- ExcelWorksheet sheet = workBook.Worksheets.First();
- int lastRow = sheet.Cells.Count() / 2;
- var cells = sheet.Cells[string.Format("B2:B{0}", lastRow)];
- var cellsToWrite = sheet.Cells[string.Format("A2:A{0}", lastRow)];
- int cellsCount = cells.Count();
- for (int i = 1; i < 200; i++)
- {
- var currentCell = cells[i, 2];
- var currentCellToWrite = cellsToWrite[i, 1];
- int currentCellWordsCount = currentCell.Text.Split().Count();
- if (currentCellWordsCount == 1)
- {
- browser.Navigate().GoToUrl("http://dictionary.reference.com/browse/" + currentCell.Value);
- try
- {
- var element = browser.FindElementByClassName("ipapron");
- Console.WriteLine($"{i}.{element.Text}");
- currentCellToWrite.Value = element.Text;
- }
- catch (Exception)
- {
- Console.WriteLine($"{i}.Error!");
- currentCellToWrite.Style.Font.Bold = true;
- //currentCellToWrite.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.LightGray;
- //currentCellToWrite.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Red);
- currentCellToWrite.Value = "#Error#";
- }
- }
- else
- {
- Console.WriteLine($"{i}.*** words count > 1");
- currentCellToWrite.Style.Font.Bold = true;
- currentCellToWrite.Value = "***";
- }
- }
- package.Save();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement