Beispiel #1
0
# As you may have noticed, there are lots of columns available
# I did what I could to make them easily-accessible, but there
# are a lot, and the names are long. So, the API calls have
# defaults

# Let's get some URL metrics. Results are now an array of dictionaries
# the i'th dictionary is the results for the i'th URL
metrics = client.urlMetrics(['www.moz.com', 'www.moz.com/blog'])
# Now let's say we only want specific columns in the results
authorities = client.urlMetrics(['www.moz.com'],
                                Mozscape.UMCols.domainAuthority
                                | Mozscape.UMCols.pageAuthority)
# Or if you just need results for one URL
mozMetrics = client.urlMetrics('www.moz.com')

# Now for some anchor text results
anchorResults = client.anchorText('www.moz.com/blog')
# Or for just specific columns
anchorTermResults = client.anchorText('www.moz.com/blog',
                                      cols=Mozscape.ATCols.term)

# Now for some links results
links = client.links('www.moz.com')
# The links API has more columns to specify, as well as sort, scope, etc.
links = client.links('www.moz.com',
                     scope='domain_to_domain',
                     sort='domain_authority',
                     filters=['external', 'nofollow'],
                     targetCols=Mozscape.UMCols.url)
    'my-access-id',
    'my-secret-key')

# As you may have noticed, there are lots of columns available
# I did what I could to make them easily-accessible, but there
# are a lot, and the names are long. So, the API calls have
# defaults

# Let's get some URL metrics. Results are now an array of dictionaries
# the i'th dictionary is the results for the i'th URL
metrics = client.urlMetrics(['www.moz.com', 'www.moz.com/blog'])
# Now let's say we only want specific columns in the results
authorities = client.urlMetrics(
    ['www.moz.com'],
    Mozscape.UMCols.domainAuthority | Mozscape.UMCols.pageAuthority)
# Or if you just need results for one URL
mozMetrics = client.urlMetrics('www.moz.com')

# Now for some anchor text results
anchorResults = client.anchorText('www.moz.com/blog')
# Or for just specific columns
anchorTermResults = client.anchorText(
    'www.moz.com/blog', cols=Mozscape.ATCols.term)

# Now for some links results
links = client.links('www.moz.com')
# The links API has more columns to specify, as well as sort, scope, etc.
links = client.links(
    'www.moz.com', scope='domain_to_domain', sort='domain_authority',
    filters=['external', 'nofollow'], targetCols=Mozscape.UMCols.url)
links = client.links('ENTER URL',
                     scope='page_to_page',
                     sort='page_authority',
                     filters=['internal'],
                     targetCols=Mozscape.UMCols.url)

## PUT ABOVE INTO A PANDAS DATAFRAME ##
#df = pd.DataFrame(authorities.items())
df = pd.DataFrame(links)
df = df.rename(columns={'upa': 'Page Authority', 'uu': 'URL'})

print(df)
df.to_excel('mozLinks.xls', index=False)
# use xlsx to stop limiting of row export - check csv module

anchorTermResults = client.anchorText('ENTER_URL',
                                      cols=Mozscape.ATCols.freeCols2)

df2 = pd.DataFrame(anchorTermResults)
df2 = df2.rename(
    columns={
        'apuemp': 'External Mozrank passed',
        'apuimp': 'Internal Mozrank Passed',
        'apuiu': 'Internal Pages Linking',
        'aput': 'Term'
    })
print(df2)

df2.to_excel('anchors.xls', index=False)
# print(df)
"""
default metrics when doing print(mozMetrics)