How to parse the data from Google Alerts?

google alerts rss
google alerts set up
myaccount google com alert
google alerts api php
google alert center
google trends alerts
google alerts api python
google alerts paid

Firstly, How would you get Google Alerts information into a database other than to parse the text of the email message that Google sends you?

It seems that there is no Google Alerts API.

If you must parse text, how would you go about parsing out the relevant pieces of the email message?

When you create the alert, set the "Deliver To" to "Feed" and then you can consume the feed XML as you would any other feed. This is much easier to parse and digest into a database.

Export Google Alerts to a spreadsheet in 5 easy steps, So what we're going to do is to use an email parser to transform Google Alert notifications into properly formatted data that we can download as  Export Google Alerts to a spreadsheet in 5 easy steps. Step 1: Create a Parseur account. If you don't have an account already, create a Parseur account . Parseur is totally and forever free for a Step 2: Create a mailbox. Step 3: forward your Google Alerts to your mailbox. Step 4: automate

class googleAlerts{
    public function createAlert($alert){
        $USERNAME = 'XXXXXX@gmail.com';
        $PASSWORD = 'YYYYYY';
        $COOKIEFILE = 'cookies.txt';

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_COOKIEJAR, $COOKIEFILE);
        curl_setopt($ch, CURLOPT_COOKIEFILE, $COOKIEFILE);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
        curl_setopt($ch, CURLOPT_TIMEOUT, 120);

        curl_setopt($ch, CURLOPT_URL,
            'https://accounts.google.com/ServiceLogin?hl=en&service=alerts&continue=http://www.google.com/alerts/manage');
        $data = curl_exec($ch);

        $formFields = $this->getFormFields($data);

        $formFields['Email']  = $USERNAME;
        $formFields['Passwd'] = $PASSWORD;
        unset($formFields['PersistentCookie']);

        $post_string = '';
        foreach($formFields as $key => $value) {
            $post_string .= $key . '=' . urlencode($value) . '&';
        }

        $post_string = substr($post_string, 0, -1);

        curl_setopt($ch, CURLOPT_URL, 'https://accounts.google.com/ServiceLoginAuth');
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);

        $result = curl_exec($ch);

        if (strpos($result, '<title>') === false) {
            return false;

        } else {
            curl_setopt($ch, CURLOPT_URL, 'http://www.google.com/alerts');
            curl_setopt($ch, CURLOPT_POST, 0);
            curl_setopt($ch, CURLOPT_POSTFIELDS, null);

            $result = curl_exec($ch);

            curl_setopt($ch, CURLOPT_URL, 'http://www.google.com/alerts/create');
            curl_setopt($ch, CURLOPT_POST, 0);
            $result = curl_exec($ch);
            //var_dump($result);
            $result = $this->getFormFieldsCreate($result);
            $result['q'] = $alert;
            $result['t'] = '7';
            $result['f'] = '1';
            $result['l'] = '0';
            $result['e'] = 'feed';
            unset($result['PersistentCookie']);

            $post_string = '';
            foreach($result as $key => $value) {
                $post_string .= $key . '=' . urlencode($value) . '&';
            }

            $post_string = substr($post_string, 0, -1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
            $result = curl_exec($ch);
            curl_setopt($ch, CURLOPT_URL, 'http://www.google.com/alerts/manage');
            $result = curl_exec($ch);
            if (preg_match_all('%'.$alert.'(?=</a>).*?<a href=[\'"]http://www.google.com/alerts/feeds/([^\'"]+)%i', $result, $matches)) {
                return ('http://www.google.com/alerts/feeds/'.$matches[1][0]);
            } else {
                return false;
            }


        }
    }

    private function getFormFields($data)
    {
        if (preg_match('/(<form.*?id=.?gaia_loginform.*?<\/form>)/is', $data, $matches)) {
            $inputs = $this->getInputs($matches[1]);

            return $inputs;
        } else {
            die('didnt find login form');
        }
    }
    private function getFormFieldsCreate($data)
    {
        if (preg_match('/(<form.*?name=.?.*?<\/form>)/is', $data, $matches)) {
            $inputs = $this->getInputs($matches[1]);

            return $inputs;
        } else {
            die('didnt find login form1');
        }
    }


    private function getInputs($form)
    {
        $inputs = array();

        $elements = preg_match_all('/(<input[^>]+>)/is', $form, $matches);

        if ($elements > 0) {
            for($i = 0; $i < $elements; $i++) {
                $el = preg_replace('/\s{2,}/', ' ', $matches[1][$i]);

                if (preg_match('/name=(?:["\'])?([^"\'\s]*)/i', $el, $name)) {
                    $name  = $name[1];
                    $value = '';

                    if (preg_match('/value=(?:["\'])?([^"\'\s]*)/i', $el, $value)) {
                        $value = $value[1];
                    }

                    $inputs[$name] = $value;
                }
            }
        }

        return $inputs;
    }
}
$alert = new googleAlerts;
echo $alert->createAlert('YOUR ALERT');

It will return link to rss feed of your newly created alert

Is it possible to get the Google Alerts as structured data , Google Alerts allows you to setup an RSS feed for the alert delivery. That'll probably be your best bet to get the data in a structured form. Go to Google Alerts. Next to an alert, click Edit . If you don’t see any options, click Show options. Make your changes. Click Update Alert. To change how you get alerts, click Settings check the options you want and click Save. Delete an alert. Go to Google Alerts. Next to the alert you want to remove, click Delete .

I found a Google Alerts API here. It's pretty minimal and I haven't tested it.

Pulling Data from Google Alert Emails - Data for Insulin, Do you have Google Alert emails as far back as the beginning of time? get at the underlying data (even your own!) in their systems — especially email. by iterating through each PDF and parsing the PDF using pdfquery. We can maintain the fetched/processed alerts against their title hashes and only honor the delta / new google alerts in our iterations, this may be the v2.0 of “retrieving google alerts on Covid

Google Alerts RSS Feed classification · alessandrousseglioviretta , Google Alerts RSS Feeds: retrieval, analysis and classification import feedparser from bs4 import BeautifulSoup # print the titles of the feeds d = feedparser.parse('http://www.google.com/alerts/ FORMAT, data=payload, headers=headers). You plain copy-pasted the code from an answer here on SO. Sure it will not work without at least trying to get the exact names out of that XML. enclosure is not in that feed results.

How to parse the data from Google Alerts?, Firstly, How would you get Google Alerts information into a database other than to parse the text of the email message that Google sends you? Irina Shamaeva recently posted a link to this page which talks about converting your Google search results to an RSS feed. I decided to explore taking this a step further - if I can convert it to RSS, then can I import these results into a spreadsheet? With the assistance from Aaron Lintz and David Galley (to bounce ideas off of), I took a look at Excel and Google Docs to do this. First Things

If I have three months of once-a-day Google Alert emails, what is the , months of once-a-day Google Alert emails, what is the best way to crowdsource and extract relevant articles, quotes, sources, and reporters from that data? While there is some change in the way words are used, new slang, etc, excluding keywords to avoid patterns of Google Alerts and topics is generally a one-time thing: set up the Google Alert, examine several pages of search results, and tweak your alert to maximize its usefulness.

Comments
  • I know this post is a bit old, but after searching a lot, I finally found a working php library to programmatically read, delete and create google alerts: http://coders11.com/googlealertsapi
  • Where is the api? I cant find any documents of using google alerts api
  • It's not so much an API as just a feed URL. See thenextweb.com/google/2013/09/11/… it shows how to manage your Google Alerts RSS feed and get the URL.
  • I haven't tested the code - But like you have shared the code to create an alert, is there some code to delete or edit alerts also?
  • For future readers, as of this day this solution no longer works.