Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to run Canopy in .fsi? #509

Open
jamessdixon opened this issue Jan 3, 2021 · 7 comments
Open

How to run Canopy in .fsi? #509

jamessdixon opened this issue Jan 3, 2021 · 7 comments

Comments

@jamessdixon
Copy link

Chris:

I am trying to use Canopy to scrape some web pages - pass in a uri and getting the html document from a page (after the javascript runs)

I opened .fsi and wrote this code:
#r "nuget: Canopy"
#r "nuget: Selenium.WebDriver.ChromeDriver"

open canopy.classic
open canopy.configuration
open canopy.runner.classic

//canopy.configuration.chromeDir <- System.AppContext.BaseDirectory
canopy.configuration.chromeDir <- executingDir
canopy.configuration.elementTimeout <- 3.0
canopy.configuration.pageTimeout <- 3.0
let reporter = canopy.reporters.LiveHtmlReporter(Chrome, canopy.configuration.chromeDir) :> canopy.reporters.IReporter
canopy.classic.start(canopy.types.BrowserStartMode.Chrome, reporter)
let url = "https://finance.yahoo.com/quote/MSFT/press-releases"
canopy.classic.url(url)

except IReporter is defined in the ConsoleReporter type?
Am I even on the right track to do this?

@lefthandedgoat
Copy link
Owner

@jamessdixon

Since you are using f# you dont have to fully qualify all of your functions. The code snippet on this page will get you part way there:

http://lefthandedgoat.github.io/canopy/

configuration.chromeDir <- executingDir()
reporter <- new LiveHtmlReporter(Chrome, configuration.chromeDir) :> IReporter

start chrome

url "https://finance.yahoo.com/quote/MSFT/press-releases"

that should get you there, if you have any specific errors let me know

@lefthandedgoat
Copy link
Owner

Also here is another thread that may help you. #457

@amirrajan
Copy link
Collaborator

The zip file here will help: #385

It's really really old, but the structure should be about the same

@jamessdixon
Copy link
Author

jamessdixon commented Jan 3, 2021 via email

@lefthandedgoat
Copy link
Owner

lefthandedgoat commented Jan 3, 2021

Something like

let marketCap = read "[data-test='MARKET_CAP-value'] span"

from: https://lefthandedgoat.github.io/canopy//Docs/actions.html

canopy lets you use xpath/css/jquery selectors by default. You can use $$("valid css selector") in chrome dev tools to test your selectors like the one above. Here is a handy cheat sheet: https://oscarotero.com/jquery/

You may be better off using an http api to get your stock data, scraping webpages is painful.

I was looking into this one recently: https://www.alphavantage.co/

@jamessdixon
Copy link
Author

jamessdixon commented Jan 4, 2021 via email

@amirrajan
Copy link
Collaborator

this might help you with http stuff: https://github.com/amirrajan/exploring-fsharp/blob/master/002/002.fsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants