Free Software: ranker.py - Find your position on Google SERPS

Status
Not open for further replies.

uncouth1

Newbie
Joined
Aug 11, 2023
Messages
28
Reaction score
16
Ranker.py

Reveal SERPS Position on Google.


Code:
Usage:
> python .\ranker.py --url "carfax.com" --keyword "best car deals"
You rank 10 for: www.carfax.com/blog/best-car-deals with keyword: best car deals
You rank 49 for: www.carfax.com/blog/0-apr-car-deals with keyword: best car deals


This software is simple, simply copy it into a .py file (ranker.py). If you want an .exe that runs on Windows, let me know and I will PM, or do it yourself with:

Code:
pyinstaller --onefile ranker.py

If you encounter bugs or something isn't working right, let me know.

Python:
import argparse
from typing import List, Tuple, Any
import mechanize
import re


class GoogleRank:
    def __init__(self, url: str, rank_url: str, keyword: str) -> None:
        self.search_url: str = url
        self.rank_url: str = rank_url
        self.rank_keyword: str = keyword
        self.br: mechanize.Browser = mechanize.Browser()
        self.br.set_handle_robots(False)
        self.useragent: List[Tuple[str, str]] = [
            ('User-agent', 'Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko')
        ]
        self.br.addheaders = self.useragent

    def get_serp_links(self) -> List[str]:
        self.br.open(self.search_url + self.rank_keyword)
        response = self.br.response().read()
        links = re.findall(r'href="/url\?.*?"><', str(response))

        parsed_link: List[str] = []
        for link in links:
            split_link = link.split('=')
            split_link = link.split('https://')
            split_link = split_link[1].split('&')
            parsed_link.append(f"{split_link[0]}")

        return parsed_link

    def get_rank(self) -> Tuple[List[str], List[str]]:
        i: int = 1
        ranked: List[str] = []
        full_serp: List[str] = []
        links: List[str] = self.get_serp_links()
        for link in links:
            if self.rank_url in link:
                text: str = f"You rank {i} for: {link} with keyword: {self.rank_keyword}"

                ranked.append(text)
            else:
                full_serp.append(f"{i}: {link}")
            i += 1
        return ranked, full_serp


def main() -> None:
    parser: argparse.ArgumentParser = argparse.ArgumentParser(description="Get Google SERP rank in top 100.")
    parser.add_argument('--url', '-u', required=True, type=str,
                        default=None, dest="rank_url",
                        help="Provide a full URL which you'd like to check on Google SERPS (e.g. truecars.com/cars).")
    parser.add_argument('--keyword', '-k', required=True, type=str,
                        default=None, dest='keyword',
                        help='Provide a keyword phrase (e.g. best car deals).')
    args: argparse.Namespace = parser.parse_args()

    goog: GoogleRank = GoogleRank("https://www.google.com/search?num=100&q=", args.rank_url, args.keyword)
    ranked: List[str] = goog.get_rank()[0]
    full_serp: Any = goog.get_rank()[1]

    if ranked:
        for position in ranked:
            print(position)


if __name__ == "__main__":
    main()
 
Is it possible to expand the search to e.g. 300 items to check increasing keywords?
Yeah it should be but I won't be updating this script for right now. I.e. will require more work on the source code

Can you share the .exe file here for windows.
Your software can search first 1000 result?

I will PM you as they won't accept the link here. I'll need to build up my post count first though, so hang in there.

It does top 100 results only on Google.

Write an Android application or program for Windows.
It's helpful and easy to use for all members.

You can run this one under cmd/powershell/from an ide like PyCharm. You'll need to have Python installed though until I can get you the link in PM.
 
Status
Not open for further replies.
Back
Top