- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试从 Google 网站站长工具 (GWT) 获取一些数据,我已经搜索了一些 API 文档和工具,但它们仅从 GWT 返回了一些数据。
我的需求:
需要从GWT获取以下数据,
(1)。 TOP_PAGES
(2)。 TOP_QUERIES
(3)。 CRAWL_ERRORS
(4)。内容错误
(5)。 CONTENT_KEYWORDS
(6)。内部链接
(7)。外部链接
(8)。社会事件
获取这些数据后,我需要为每个数据生成 Excel 文件。
已实现:
我从上面得到的数据很少并生成到 Excel 文件中。例如,
(1)。 TOP_PAGES
(2)。 TOP_QUERIES
(3)。内部链接
(4)。外部链接
(5)。 CONTENT_KEYWORDS
未实现:
我仍然没有得到像这样的主要部分/数据,
(1)。 CRAWL_ERRORS
(2)。内容错误
(3)。社会事件
供您引用的代码示例:
我在 PHP 中为这个 GWT API 使用了两个文件,
文件#1: ( gwdata.php )
<?php
/**
* PHP class for downloading CSV files from Google Webmaster Tools.
*
* This class does NOT require the Zend gdata package be installed
* in order to run.
*
* Copyright 2012 eyecatchUp UG. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author: Stephan Schmitz <eyecatchup@gmail.com>
* @link: https://code.google.com/p/php-webmaster-tools-downloads/
*/
class GWTdata
{
const HOST = "https://www.google.com";
const SERVICEURI = "/webmasters/tools/";
public $_language, $_tables, $_daterange, $_downloaded, $_skipped;
private $_auth, $_logged_in;
public function __construct()
{
$this->_auth = false;
$this->_logged_in = false;
$this->_language = "en";
$this->_daterange = array("","");
$this->_tables = array("TOP_PAGES", "TOP_QUERIES",
"CRAWL_ERRORS", "CONTENT_ERRORS", "CONTENT_KEYWORDS",
"INTERNAL_LINKS", "EXTERNAL_LINKS", "SOCIAL_ACTIVITY"
);
$this->_errTablesSort = array(0 => "http",
1 => "not-found", 2 => "restricted-by-robotsTxt",
3 => "unreachable", 4 => "timeout", 5 => "not-followed",
"kAppErrorSoft-404s" => "soft404", "sitemap" => "in-sitemaps"
);
$this->_errTablesType = array(0 => "web-crawl-errors",
1 => "mobile-wml-xhtml-errors", 2 => "mobile-chtml-errors",
3 => "mobile-operator-errors", 4 => "news-crawl-errors"
);
$this->_downloaded = array();
$this->_skipped = array();
}
/**
* Sets content language.
*
* @param $str String Valid ISO 639-1 language code, supported by Google.
*/
public function SetLanguage($str)
{
$this->_language = $str;
}
/**
* Sets features that should be downloaded.
*
* @param $arr Array Valid array values are:
* "TOP_PAGES", "TOP_QUERIES", "CRAWL_ERRORS", "CONTENT_ERRORS",
* "CONTENT_KEYWORDS", "INTERNAL_LINKS", "EXTERNAL_LINKS",
* "SOCIAL_ACTIVITY".
*/
public function SetTables($arr)
{
if(is_array($arr) && !empty($arr) && sizeof($arr) <= 2) {
$valid = array("TOP_PAGES","TOP_QUERIES","CRAWL_ERRORS","CONTENT_ERRORS",
"CONTENT_KEYWORDS","INTERNAL_LINKS","EXTERNAL_LINKS","SOCIAL_ACTIVITY");
$this->_tables = array();
for($i=0; $i < sizeof($arr); $i++) {
if(in_array($arr[$i], $valid)) {
array_push($this->_tables, $arr[$i]);
} else { throw new Exception("Invalid argument given."); }
}
} else { throw new Exception("Invalid argument given."); }
}
/**
* Sets daterange for download data.
*
* @param $arr Array Array containing two ISO 8601 formatted date strings.
*/
public function SetDaterange($arr)
{
if(is_array($arr) && !empty($arr) && sizeof($arr) == 2) {
if(self::IsISO8601($arr[0]) === true &&
self::IsISO8601($arr[1]) === true) {
$this->_daterange = array(str_replace("-", "", $arr[0]),
str_replace("-", "", $arr[1]));
return true;
} else { throw new Exception("Invalid argument given."); }
} else { throw new Exception("Invalid argument given."); }
}
/**
* Returns array of downloaded filenames.
*
* @return Array Array of filenames that have been written to disk.
*/
public function GetDownloadedFiles()
{
return $this->_downloaded;
}
/**
* Returns array of downloaded filenames.
*
* @return Array Array of filenames that have been written to disk.
*/
public function GetSkippedFiles()
{
return $this->_skipped;
}
/**
* Checks if client has logged into their Google account yet.
*
* @return Boolean Returns true if logged in, or false if not.
*/
private function IsLoggedIn()
{
return $this->_logged_in;
}
/**
* Attempts to log into the specified Google account.
*
* @param $email String User's Google email address.
* @param $pwd String Password for Google account.
* @return Boolean Returns true when Authentication was successful,
* else false.
*/
public function LogIn($email, $pwd)
{
$url = self::HOST . "/accounts/ClientLogin";
$postRequest = array(
'accountType' => 'HOSTED_OR_GOOGLE',
'Email' => $email,
'Passwd' => $pwd,
'service' => "sitemaps",
'source' => "Google-WMTdownloadscript-0.1-php"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postRequest);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if($info['http_code'] == 200) {
preg_match('/Auth=(.*)/', $output, $match);
if(isset($match[1])) {
$this->_auth = $match[1];
$this->_logged_in = true;
return true;
} else { return false; }
} else { return false; }
}
/**
* Attempts authenticated GET Request.
*
* @param $url String URL for the GET request.
* @return Mixed Curl result as String,
* or false (Boolean) when Authentication fails.
*/
public function GetData($url)
{
if(self::IsLoggedIn() === true) {
$url = self::HOST . $url;
$head = array("Authorization: GoogleLogin auth=".$this->_auth,
"GData-Version: 2");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_ENCODING, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $head);
$result = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
return ($info['http_code']!=200) ? false : $result;
} else { return false; }
}
/**
* Gets all available sites from Google Webmaster Tools account.
*
* @return Mixed Array with all site URLs registered in GWT account,
* or false (Boolean) if request failed.
*/
public function GetSites()
{
if(self::IsLoggedIn() === true) {
$feed = self::GetData(self::SERVICEURI."feeds/sites/");
if($feed !== false) {
$sites = array();
$doc = new DOMDocument();
$doc->loadXML($feed);
foreach ($doc->getElementsByTagName('entry') as $node) {
array_push($sites,
$node->getElementsByTagName('title')->item(0)->nodeValue);
}
return $sites;
} else { return false; }
} else { return false; }
}
/**
* Gets the download links for an available site
* from the Google Webmaster Tools account.
*
* @param $url String Site URL registered in GWT.
* @return Mixed Array with keys TOP_PAGES and TOP_QUERIES,
* or false (Boolean) when Authentication fails.
*/
public function GetDownloadUrls($url)
{
if(self::IsLoggedIn() === true) {
$_url = sprintf(self::SERVICEURI."downloads-list?hl=%s&siteUrl=%s",
$this->_language,
urlencode($url));
$downloadList = self::GetData($_url);
return json_decode($downloadList, true);
} else { return false; }
}
/**
* Downloads the file based on the given URL.
*
* @param $site String Site URL available in GWT Account.
* @param $savepath String Optional path to save CSV to (no trailing slash!).
*/
public function DownloadCSV($site, $savepath=".")
{
if(self::IsLoggedIn() === true) {
$downloadUrls = self::GetDownloadUrls($site);
$filename = parse_url($site, PHP_URL_HOST) ."-". date("Ymd-His");
$tables = $this->_tables;
foreach($tables as $table) {
if($table=="CRAWL_ERRORS") {
self::DownloadCSV_CrawlErrors($site, $savepath);
}
elseif($table=="CONTENT_ERRORS") {
self::DownloadCSV_XTRA($site, $savepath,
"html-suggestions", "\)", "CONTENT_ERRORS", "content-problems-dl");
}
elseif($table=="CONTENT_KEYWORDS") {
self::DownloadCSV_XTRA($site, $savepath,
"keywords", "\)", "CONTENT_KEYWORDS", "content-words-dl");
}
elseif($table=="INTERNAL_LINKS") {
self::DownloadCSV_XTRA($site, $savepath,
"internal-links", "\)", "INTERNAL_LINKS", "internal-links-dl");
}
elseif($table=="EXTERNAL_LINKS") {
self::DownloadCSV_XTRA($site, $savepath,
"external-links-domain", "\)", "EXTERNAL_LINKS", "external-links-domain-dl");
}
elseif($table=="SOCIAL_ACTIVITY") {
self::DownloadCSV_XTRA($site, $savepath,
"social-activity", "x26", "SOCIAL_ACTIVITY", "social-activity-dl");
}
else {
$finalName = "$savepath/$table-$filename.csv";
$finalUrl = $downloadUrls[$table] ."&prop=ALL&db=%s&de=%s&more=true";
$finalUrl = sprintf($finalUrl, $this->_daterange[0], $this->_daterange[1]);
self::SaveData($finalUrl,$finalName);
}
}
} else { return false; }
}
/**
* Downloads "unofficial" downloads based on the given URL.
*
* @param $site String Site URL available in GWT Account.
* @param $savepath String Optional path to save CSV to (no trailing slash!).
*/
public function DownloadCSV_XTRA($site, $savepath=".", $tokenUri, $tokenDelimiter, $filenamePrefix, $dlUri)
{
if(self::IsLoggedIn() === true) {
$uri = self::SERVICEURI . $tokenUri . "?hl=%s&siteUrl=%s";
$_uri = sprintf($uri, $this->_language, $site);
$token = self::GetToken($_uri, $tokenDelimiter);
$filename = parse_url($site, PHP_URL_HOST) ."-". date("Ymd-His");
$finalName = "$savepath/$filenamePrefix-$filename.csv";
$url = self::SERVICEURI . $dlUri . "?hl=%s&siteUrl=%s&security_token=%s&prop=ALL&db=%s&de=%s&more=true";
$_url = sprintf($url, $this->_language, $site, $token, $this->_daterange[0], $this->_daterange[1]);
self::SaveData($_url,$finalName);
} else { return false; }
}
/**
* Downloads the Crawl Errors file based on the given URL.
*
* @param $site String Site URL available in GWT Account.
* @param $savepath String Optional: Path to save CSV to (no trailing slash!).
* @param $separated Boolean Optional: If true, the method saves separated CSV files
* for each error type. Default: Merge errors in one file.
*/
public function DownloadCSV_CrawlErrors($site, $savepath=".", $separated=false)
{
if(self::IsLoggedIn() === true) {
$type_param = "we";
$filename = parse_url($site, PHP_URL_HOST) ."-". date("Ymd-His");
if($separated) {
foreach($this->_errTablesSort as $sortid => $sortname) {
foreach($this->_errTablesType as $typeid => $typename) {
if($typeid == 1) {
$type_param = "mx";
} else if($typeid == 2) {
$type_param = "mc";
} else {
$type_param = "we";
}
$uri = self::SERVICEURI."crawl-errors?hl=en&siteUrl=$site&tid=$type_param";
$token = self::GetToken($uri,"x26");
$finalName = "$savepath/CRAWL_ERRORS-$typename-$sortname-$filename.csv";
$url = self::SERVICEURI."crawl-errors-dl?hl=%s&siteUrl=%s&security_token=%s&type=%s&sort=%s";
$_url = sprintf($url, $this->_language, $site, $token, $typeid, $sortid);
self::SaveData($_url,$finalName);
}
}
}
else {
$uri = self::SERVICEURI."crawl-errors?hl=en&siteUrl=$site&tid=$type_param";
$token = self::GetToken($uri,"x26");
$finalName = "$savepath/CRAWL_ERRORS-$filename.csv";
$url = self::SERVICEURI."crawl-errors-dl?hl=%s&siteUrl=%s&security_token=%s&type=0";
$_url = sprintf($url, $this->_language, $site, $token);
self::SaveData($_url,$finalName);
}
} else { return false; }
}
/**
* Saves data to a CSV file based on the given URL.
*
* @param $finalUrl String CSV Download URI.
* @param $finalName String Filepointer to save location.
*/
private function SaveData($finalUrl, $finalName)
{
$data = self::GetData($finalUrl);
if(strlen($data) > 1 && file_put_contents($finalName, utf8_decode($data))) {
array_push($this->_downloaded, realpath($finalName));
return true;
} else {
array_push($this->_skipped, $finalName);
return false;
}
}
/**
* Regular Expression to find the Security Token for a download file.
*
* @param $uri String A Webmaster Tools Desktop Service URI.
* @param $delimiter String Trailing delimiter for the regex.
* @return String Returns a security token.
*/
private function GetToken($uri, $delimiter)
{
$matches = array();
$tmp = self::GetData($uri);
//preg_match_all("#x26security_token(.*?)$delimiter#si", $tmp, $matches);
preg_match_all("#46security_token(.*?)$delimiter#si", $tmp, $matches);
//return substr($matches[1][0],4,-1);
return substr($matches[1][0],3,-1);
}
/**
* Validates ISO 8601 date format.
*
* @param $str String Valid ISO 8601 date string (eg. 2012-01-01).
* @return Boolean Returns true if string has valid format, else false.
*/
private function IsISO8601($str)
{
$stamp = strtotime($str);
return (is_numeric($stamp) && checkdate(date('m', $stamp),
date('d', $stamp), date('Y', $stamp))) ? true : false;
}
}
?>
文件#2: ( index.php )
<?php
include 'gwtdata.php';
include 'credentials.php';
try {
$website = "http://www.yourdomain.com/"; /* Add Your Website Url */
$gdata = new GWTdata();
if($gdata->LogIn($email, $password) === true)
{
$gdata->DownloadCSV($website,"Here Add Your Folder Path To Save CSV File With GWT Data");
echo "Datas Are Successfully Downloaded";
}
} catch (Exception $e) {
die($e->getMessage());
}
?>
任何人都可以帮助我实现所有这些数据并将其制作为 excel 文件以使用 PHP 生成。
最佳答案
[..] I have searched some of the API Documents and Implements, [..]
[..] I have used two files in PHP for this GWT API, [..]
我是您引用的代码(GWTdata PHP 类)的作者,首先要明确表示此代码既不由 Google 发布也不使用一个官方 API,而是一个自定义脚本,用于处理来自 Web 界面的数据。
[..] returning few of the datas only from the GWT. [..]
几周前,Google 网站站长工具网络界面发生了一些变化(同样,它曾经/现在用于处理数据请求)。因此,它破坏了 PHP 类 GWTdata 的某些功能 - 例如下载爬网错误。
[..] Can anyone help me in this, to achieve all those datas and make it as excel file to generate using PHP. [..]
不幸的是,对于大多数数据,我/我们对此无能为力(因为数据不再可访问)。
[..] Still I'm not getting the major parts / datas like,
1. Crawl errors [..]
无论如何,你可以使用this followup project获取抓取错误。
GwtCrawlErrors(以 CSV 格式从 Google 网站站长工具下载网站抓取错误):
https://github.com/eyecatchup/GWT_CrawlErrors-php
关于php - 是否有可能使用 PHP 获取 Google 网站管理员工具 (GET) 数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15611372/
有没有办法为 Sinatra 获取 Django Admin 风格的网络管理员? 最佳答案 没用过,但通过谷歌很快就显示出来了:http://www.padrinorb.com/ 关于ruby - S
我正在开发一个 Wordpress 插件,它为不同的用户(管理员、编辑、作者、贡献者、订阅者)提供不同的权限。我已经能够使该插件在管理员面板或页面/末尾完美运行,但是当我以编辑身份登录时,我无法在他们
在为 Web 应用程序用例图建模时,为用户可以拥有的每个角色创建一个角色是否更好?或拥有一个角色、用户和一个具有特权的矩阵? guest < 用户 < 版主 < 管理员 1: guest 、用户、版主
Tibco Administrator GUI 在哪里获取应用程序和服务的状态? 在我的项目中,我需要读取 Tibco admin 中列出的所有服务的状态。我没有安装 Tibco hawk,我需要除
我们最近将我们的多域 magento 设置从共享主机迁移到专用服务器。 一切正常,但是当我尝试转到管理部分时,登录后出现任何 404 错误。 如果我从 url 中删除 index.php 似乎可以工作
我有一个多对多字段。我想限制管理员在其 M2M 小部件中显示的选择。 我有一个这样的模型: class A(models.Model): b_field = models.ManyToMany
我正在与其他几位同事一起使用 Azure。我们有一个共享的管理员帐户,我们所有人都可以访问该帐户(凭据)。几天前,当尝试使用管理员帐户登录 Azure 门户时,我们收到此消息:“需要更多信息。您的组织
如何使 Django 后端(和一些 View )在不同的域中可访问?是通过站点框架完成的吗? 最佳答案 创建 settings.py 的副本并使用该设置文件运行管理服务器。此外,创建 urls.py
我刚刚收到以某种方式在 Django 管理面板上显示数据的要求。实际上我有日志表,其中包含用户 ID 和它采取的操作。 class AuditTrail(models.Model): id = m
每当我访问我的网站地址/admin 时,就会出现此问题 Warning: mysqli::mysqli() [mysqli.mysqli]: (28000/1045): Access denied f
我一直在为 Django/Mysql 中的情况而苦苦挣扎。 在同时有主键和外键的表中有这一列。此列与中间表具有一对多关系。 这是与植物物种相关的状态列表。有些物种可以在多个州找到。 物种(表 1)列:
firebase 身份验证和 firebase 管理员有什么区别? 据我所知,firebase admin 具有身份验证功能,并且可以绕过安全性,这与 firebase 身份验证不同。 Firebas
我创建了一个 SonarQube 组 sonar-administrators-ldap 并映射到 LDAP sonar-administrators-ldap 。 sonar-administrat
我正在创建一个 Django 应用程序,其中所有模型都可以按照用户设置的顺序相互关联。我正在使用 GenericForeignKeys 设置所有这些。关键是我需要能够支持这些类型的关系/管理的多个集合
我无法使用我创建的任何 super 用户登录 Django 管理员。尝试创建新的 super 用户、更改密码等 - 这些进程中的任何一个都没有错误消息,但仍然无法登录。 我不确定它是否相关,但我也无法
我正在将我的 Django 项目前端从使用 jquery 转换为 angularjs与 Django Rest Framework以帮助使其成为单页应用程序。我已经用 angular 转换了大部分棘手
我正在尝试在我的管理页面中的某个 ModelView 上加载脚本: class CustomView(ModelView): # Neither approach works here:
我正在尝试在我的 rails 应用程序中设置设计。它运行良好,但现在我无法以任何用户身份登录,我收到“电子邮件或密码无效”。我想更深入地了解为什么它不进行身份验证。 是否有任何设计配置设置可以提供更多
我目前正在尝试在 drupal 中实现第二个(较低的)管理层。我通过同名模块为这些用户制作了一个额外的部分,以便他们可以拥有自己的主题等。我想在他们的页面部分中为这些二级或更低级别的管理员提供一个菜单
如何显示来自 API 服务器 React-admin 3.0 版的错误响应消息? 此变体不起作用 https://github.com/marmelab/react-admin/pull/871 en
我是一名优秀的程序员,十分优秀!