Automating Finviz Screener with Selenium in Python

avatar
(Edited)

finviz.png

Finviz is very useful website for any trader. One of its cool features is the Screener, where traders can search for assets they would like to consider for trading based on various conditions and filters. Three main categories of filters are Descriptive, Fundamental, and Technical. Go to Finviz.com and click Screener from the top menu or just go to https://finviz.com/screener.ashx to see the screener page.

A few weeks ago I decided to extend my stocks watch list because I need a larger set of stocks to experiment with various indicator strategies programmatically. I went to the Finviz and filtered higher market cap company stocks. The result showed me about 1300 stocks. Now I spent some time to manually write down each ticker symbol and went through dozens of pages. It was a tedious work. Since it was a one time thing, it didn't bother. I need a large list of stocks for backtesting.

After I was done writing them all down in a list, it was time to put the python scripts to work. I spent even more time to correcting the list. Obviously, typing all 1300+ symbols in there will be some errors. So, the code kept halting and saying this ticker symbol doesn't exist. Eventually I was able to fix them all.

The point of the story is that all of this could have been avoided if I chose to write a simple code in python using Selenium to extract all the ticker symbols I need and make a list for me. It would save a lot of time, and the list most likely would be accurate.

Today, I was able to accomplish this project. The code doesn't only do what I described above, but due to the large amount options Finviz provides to screen the assets, the code can be modified to get a list of stocks based on the filters we choose to use on daily basis.

One of the experienced traders I follow on twitter, @traderstewie once shared one of the methods he finds stocks on Finviz. It is a very simple strategy. He suggested looking for stocks that reached new high in the 52-Week High/Low range with a current volume of 300K or more. So the code I wrote does exactly that.

First thing we need to do is to go Finviz Screener page - https://finviz.com/screener.ashx. Then in Descriptive category, we will select Over 300K under Current Volume. Afterwards we move the Technical category, and select New High under 52-Week High/Low. One make these changes the url changes to the following:

https://finviz.com/screener.ashx?v=111&f=sh_curvol_o300,ta_highlow52w_nh

This will be our base url used to automate the rest of the work. As you can see on the page, there is a list of 20 stocks with various information related to each. All we need is the stock names. That's what the code is going to do. It will find the elements where the stock names are located and store them in a list.

Next same process needs to be repeated for each of the following pages. In this case there are total of 8 pages displaying stocks in the same way. The code will figure out number of pages first. Then if will create a list of urls for each page. And finally, repeats the same process for each page and prints out the full list of stocks.

I am including the screenshot of the code below. It is very simple and easy to read. If you have any interesting trading strategies you would like to share feel free to do so in the comments. Thank you for reading.

finviz_selenium.png

Posted Using LeoFinance



0
0
0.000
4 comments
avatar

Congratulations @geekgirl! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s) :

You received more than 75000 upvotes. Your next target is to reach 80000 upvotes.

You can view your badges on your board And compare to others on the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Do not miss the last post from @hivebuzz:

Project Activity Update
The Customization Guide for the HiveBuzz store
0
0
0.000