How to get data from google trends by country

Authors: CodeToday | Google Trends | Views: 946 | Posted: 08 AM: 09/09/2017

How to get data from google trends by countryGoogle search gives the user a very useful tool that is google trends. This tool allows users to know at the present time which keywords are most searched real-world people, based on which the user can make appropriate advertising methods.

In this tutorial I will show how to get data from google trends by country specific, there is a list of countries with filtered paths.


 See Also: How to compare keywords with google trends


Knowledge needed to know in this article

  1. curl_init(): Get data from https://trends.google.com/trends/hottrends/atom/feed?pn=p[...]
  2. Xml regular expression: Analysis of data structure according to xml

List of url countries according to google trends

https://trends.google.com/trends/hottrends/atom/feed?pn=p30 Argentina
https://trends.google.com/trends/hottrends/atom/feed?pn=p8 Australia
https://trends.google.com/trends/hottrends/atom/feed?pn=p44 Austria
https://trends.google.com/trends/hottrends/atom/feed?pn=p41 Belgium
https://trends.google.com/trends/hottrends/atom/feed?pn=p18 Brazil
https://trends.google.com/trends/hottrends/atom/feed?pn=p13 Canada
https://trends.google.com/trends/hottrends/atom/feed?pn=p38 Chile
https://trends.google.com/trends/hottrends/atom/feed?pn=p32 Colombia
https://trends.google.com/trends/hottrends/atom/feed?pn=p43 Czech Republic
https://trends.google.com/trends/hottrends/atom/feed?pn=p29 Egypt
https://trends.google.com/trends/hottrends/atom/feed?pn=p50 Finland
https://trends.google.com/trends/hottrends/atom/feed?pn=p16 France
https://trends.google.com/trends/hottrends/atom/feed?pn=p15 Germany
https://trends.google.com/trends/hottrends/atom/feed?pn=p48 Greece
https://trends.google.com/trends/hottrends/atom/feed?pn=p10 Hong Kong
https://trends.google.com/trends/hottrends/atom/feed?pn=p45 Hungary
https://trends.google.com/trends/hottrends/atom/feed?pn=p3 India
https://trends.google.com/trends/hottrends/atom/feed?pn=p19 Indonesia
https://trends.google.com/trends/hottrends/atom/feed?pn=p6 Israel
https://trends.google.com/trends/hottrends/atom/feed?pn=p27 Italy
https://trends.google.com/trends/hottrends/atom/feed?pn=p4 Japan
https://trends.google.com/trends/hottrends/atom/feed?pn=p37 Kenya
https://trends.google.com/trends/hottrends/atom/feed?pn=p34 Malaysia
https://trends.google.com/trends/hottrends/atom/feed?pn=p21 Mexico
https://trends.google.com/trends/hottrends/atom/feed?pn=p17 Netherlands
https://trends.google.com/trends/hottrends/atom/feed?pn=p53 New Zealand
https://trends.google.com/trends/hottrends/atom/feed?pn=p52 Nigeria
https://trends.google.com/trends/hottrends/atom/feed?pn=p51 Norway
https://trends.google.com/trends/hottrends/atom/feed?pn=p25 Philippines
https://trends.google.com/trends/hottrends/atom/feed?pn=p31 Poland
https://trends.google.com/trends/hottrends/atom/feed?pn=p39 Romania
https://trends.google.com/trends/hottrends/atom/feed?pn=p14 Russia
https://trends.google.com/trends/hottrends/atom/feed?pn=p36 Saudi Arabia
https://trends.google.com/trends/hottrends/atom/feed?pn=p5 Singapore
https://trends.google.com/trends/hottrends/atom/feed?pn=p40 South Africa
https://trends.google.com/trends/hottrends/atom/feed?pn=p23 South Korea
https://trends.google.com/trends/hottrends/atom/feed?pn=p26 Spain
https://trends.google.com/trends/hottrends/atom/feed?pn=p42 Sweden
https://trends.google.com/trends/hottrends/atom/feed?pn=p46 Switzerland
https://trends.google.com/trends/hottrends/atom/feed?pn=p12 Taiwan
https://trends.google.com/trends/hottrends/atom/feed?pn=p33 Thailand
https://trends.google.com/trends/hottrends/atom/feed?pn=p24 Turkey
https://trends.google.com/trends/hottrends/atom/feed?pn=p35 Ukraine
https://trends.google.com/trends/hottrends/atom/feed?pn=p9 United Kingdom
https://trends.google.com/trends/hottrends/atom/feed?pn=p1 United States
https://trends.google.com/trends/hottrends/atom/feed?pn=p28 Vietnam

Full PHP Source Code

Here I will take the example with usa
https://trends.google.com/trends/hottrends/atom/feed?pn=p1

<?
$url = 'https://trends.google.com/trends/hottrends/atom/feed?pn=p1';
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_HTTPGET, 1 );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION , 1 );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION , 1 );
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_REFERER, $ref );
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);     
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
$result = curl_exec($ch);
curl_close($ch);
echo '<ul>';
$trends = new SimpleXmlElement($result);
foreach($trends->channel->item as $value) { 
       $textTitle   = $value->title;
	   echo '<li>'.$textTitle.'</li>';       
}
echo '</ul>';
?>

Note: Google Trends does not limit the number of queries, so you can get unlimited

If you have any questions, please leave a message below