在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):joshcarty/google-searchconsole开源软件地址(OpenSource Url):https://github.com/joshcarty/google-searchconsole开源编程语言(OpenSource Language):Python 100.0%开源软件介绍(OpenSource Introduction):Google Search Console for Python
This package is built on top of
Google's own API Client
and is heavily inspired, from design to implementation, by @debrouwere's
fantastic QuickstartFirst, install the package using:
Then, create a new project in the Google Developers Console, enable the Google Search Console API under "APIs & Services". Next, create credentials for an OAuth client ID, choosing the Other Application type. Download a JSON copy of your client secrets. After that, executing your first query is as easy as import searchconsole
account = searchconsole.authenticate(client_config='client_secrets.json')
webproperty = account['https://www.example.com/']
report = webproperty.query.range('today', days=-7).dimension('query').get()
print(report.rows) The above example will use your client configuration file to interactively generate your credentials. Saving CredentialsIf you wish to save your credentials, to avoid going
through the OAuth consent screen in the future, you can specify a path to save
them by specifying When you want to authenticate a new account you run: account = searchconsole.authenticate(client_config='client_secrets.json',
serialize='credentials.json') Which will save your credentials to a file called From then on, you can authenticate with: account = searchconsole.authenticate(client_config='client_secrets.json',
credentials='credentials.json') Integration with Pandas DataFrameIf you wish to load your data directly into a pandas DataFrame, to avoid loading it manually after the extraction, you can do it easily: report = webproperty.query.range('today',days=-7).dimension('page').get().to_dataframe() Search typesYou can specify the search type data you want to retrieve by using the search_type method with your query. The following values are currently supported by the API: news, video, image, web, discover & googleNews. If you don't use this method, the default value used will be web, report = webproperty.query.search_type('discover').range('today',days=-7).dimension('page').get().to_dataframe() FiltersYou can apply filters while executing a query. The filter types supported by the API are the same available in the UI: contains, equals, notContains, notEquals, includingRegex & excludingRegex. report = webproperty.query.range('today',days=-7).dimension('page').filter('page','/blog/','contains').get().to_dataframe() Note that if you use Regex in your filter, you must follow RE2 syntax. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论