joshcarty / google-searchconsole

A wrapper for the Google Search Console API.
MIT License
223 stars 80 forks source link

Is there the ability to pull URLs relating to a parent project? #20

Closed SonnyDriscoll closed 5 years ago

SonnyDriscoll commented 5 years ago

Hi @joshcarty firstly great project, works really well!

I was wondering if you think there's the possibility to actually pull the URLs from Google Console that sit under the parent project?

Example: I am currently taking an export from the front-end of google search console and filtering out the URLs, then using a static list that my code loops through.

It would be much better for this list to be downloaded every time I execute the code, so as to get current results.

Any thoughts on this?

Thanks,

Sonny

joshcarty commented 5 years ago

Thanks Sonny! You can iterate through all the properties in your account with:

>>> for webproperty in account.webproperties:
        print(webproperty)
<searchconsole.account.WebProperty(url='https://www.example1.com')>
<searchconsole.account.WebProperty(url='https://www.example2.com')>
<searchconsole.account.WebProperty(url='https://www.example3.com')>

Does that make sense for your use-case?

SonnyDriscoll commented 5 years ago

Hi @joshcarty, so the solution above does indeed give me the URL's I have associated with the account, but I am looking to step one level lower to actually reveal the URL's of the sub pages contained within the site and effectively those which are under the URL's that are currently returned.

Example output:

<searchconsole.account.WebProperty(url='https://www.example1.com/')> <searchconsole.account.WebProperty(url='https://www.example2.com/')>

I am trying to get

<searchconsole.account.WebProperty(url='https://www.example1.com/subpage1')> <searchconsole.account.WebProperty(url='https://www.example1.com/subpage2')> <searchconsole.account.WebProperty(url='https://www.example1.com/subpage3')> <searchconsole.account.WebProperty(url='https://www.example1.com/subpage4')>

Does that use case make sense?

Thanks

Sonny

joshcarty commented 5 years ago

Hi @SonnyDriscoll,

It sounds like you want to dimension your site by page. You can get the top pages for a site with:

>>> webproperty = account['https://www.example.com/']
>>> report = webproperty.query.range('today', days=-7).dimension('page').get()
>>> print(report.rows)
[
    [Row(page='https://www.example.com/', clicks=10, impressions=20, ctr=0.5, position=3),
    [Row(page='https://www.example.com/subpage1', clicks=10, impressions=20, ctr=0.5, position=3),
    [Row(page='https://www.example.com/subpage2', clicks=10, impressions=20, ctr=0.5, position=3),
    [Row(page='https://www.example.com/subpage3', clicks=10, impressions=20, ctr=0.5, position=3),
    ...
]

You can also query by multiple dimensions to get queries by page, for example, with:

>>> webproperty.query.range('today', days=-7).dimension('query', 'page').get()`
[
    Row(page='https://www.example.com/', query='example', clicks=10, impressions=20, ctr=0.5, position=3)
    ...
],

Does that help?

SonnyDriscoll commented 5 years ago

Yes thats what I was looking for thanks a lot!