'How to Get Google Page Ranking All keywords Of A Specfic Domain in Python?

hi i have following code to check the position of the keyword in serp.

from googlesearch import search
import math

# to search
keyword =input("Enter the Search Keyword: ")
my_website = input("Enter Your Website: ")

# search for top 100 result
urls = search(keyword, tld="com", num=100, stop=100, pause=2)

found = False

for index, url in enumerate(urls):
  if my_website in url:
    print(f"Your Website Rank for keyword {keyword} is: {index+1}")
    print(f"And it displayed on Google Page Number:{math.ceil((index+1)/10)}")
    found = True
    break

if not found:
  print(f"Your Website is not in top 100 for keyword {keyword}")

and this is the output

`Enter the Search Keyword: best django books`
 Enter Your Website: techgeekbuzz.com
 Your Website Rank for keyword best django books is: 15
 And it displayed on Google Page Number:2`

this code works fine to get single keyword information.

I want to get all ranking keywords and there position in SERP(top 100 search results) of a given domain or page url.



Solution 1:[1]

Under the hood, the compiler is using the MulticastDelegate class when you use the delegate keyword. The delegates are called synchronously (one after another) in the order they were added. However, if you need to strictly enforce execution order, relying on the under-the-hood execution order isn't the approach I would take. It is too easy to add the handlers out of order.

To add order to the delegate calls, consider creating two delegates instead of one - notifyFirst and notifySecond. Then, you can definitively control the order in your code in a robust manner without depending on the handlers being added in the right sequence at runtime.

Solution 2:[2]

As John has already said events are executed synchronously. I would not rely on the order either. You can do something like this to enforce execution order.

var sortedSet = new SortedSet<ActionWithExecutionOrder>(
        Comparer<ActionWithExecutionOrder>.Create((x, y) =>
        {
            return x.ExecutionOrder.CompareTo(y.ExecutionOrder);
        }));

sortedSet.Add(new ActionWithExecutionOrder 
{ 
    Action = () => Console.WriteLine("First added, should be executed second."),
    ExecutionOrder = 2
});

sortedSet.Add(new ActionWithExecutionOrder
{
    Action = () => Console.WriteLine("Second added, should be executed first."),
    ExecutionOrder = 1
});

foreach(var actionWithExecutionOrder in sortedSet)
{
    actionWithExecutionOrder.Action();
}

Console.ReadLine();

class ActionWithExecutionOrder
{
    public int ExecutionOrder { get; set; }

    public Action Action { get; set; } = () => { };
}

You can do the same with delegates if you want Action has just been shorter to write for the sample. SortedSet does not allow duplicates so only one item with the same ExecutionOrder number can exist. You could use SortedList or just anything and order it after the fact. I think SortedSet is fine and you probably should throw and Exception if the key already exists and not silently ignore it. If you have two with the same key you again don“t know for sure which one executes first.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 John Glenn
Solution 2