GeneralMills/pytrends: Pseudo API for Google Trends - GitHub

文章推薦指數: 80 %
投票人數:10人

Pseudo API for Google Trends . Contribute to GeneralMills/pytrends development by creating an account on GitHub. Skiptocontent {{message}} GeneralMills / pytrends Public Notifications Fork 692 Star 2.5k PseudoAPIforGoogleTrends License Viewlicense 2.5k stars 692 forks Star Notifications Code Issues 87 Pullrequests 10 Actions Projects 0 Wiki Security Insights More Code Issues Pullrequests Actions Projects Wiki Security Insights GeneralMills/pytrends Thiscommitdoesnotbelongtoanybranchonthisrepository,andmaybelongtoaforkoutsideoftherepository. master Branches Tags Couldnotloadbranches Nothingtoshow {{refName}} default Couldnotloadtags Nothingtoshow {{refName}} default 1 branch 0 tags Code Latestcommit emlazzarin Mergepullrequest#518fromavant1/fix-request-params-passing … 706975c Jun9,2022 Mergepullrequest#518fromavant1/fix-request-params-passing fixrequests_argsusageformultiplemethods 706975c Gitstats 548 commits Files Permalink Failedtoloadlatestcommitinformation. Type Name Latestcommitmessage Committime .github/workflows Createpython-package.yml Nov26,2020 examples Mergebranch'master'intorealtime-search-trends Feb2,2022 pytrends fixrequests_argsusageformultiplemethods Jun9,2022 .gitignore Newlinein.gitignore Sep22,2017 LICENSE UpdateLICENSE Jan14,2016 MANIFEST.in includelicensefileinsourcedistribution Nov24,2020 README.md Mergepullrequest#478fromMaxGhenis/patch-1 Feb2,2022 setup.py Updatesetup.py Aug11,2020 Viewcode pytrends Introduction TableofContents Installation Requirements API ConnecttoGoogle BuildPayload APIMethods CommonAPIparameters InterestOverTime HistoricalHourlyInterest InterestbyRegion RelatedTopics RelatedQueries TrendingSearches RealtimeSearchTrends TopCharts Suggestions Categories Caveats Credits README.md pytrends Introduction UnofficialAPIforGoogleTrends AllowssimpleinterfaceforautomatingdownloadingofreportsfromGoogleTrends. OnlygooduntilGooglechangestheirbackendagain:-P.Whenthathappensfeelfreetocontribute! Lookingformaintainers!Pleaseopenanissuewithamethodofcontactingyouifyou'reinterested. TableofContents Installation API APIMethods CommonAPIParameters InterestOverTime HistoricalHourlyInterest InterestbyRegion RelatedTopics RelatedQueries TrendingSearches RealtimeSearchTrends TopCharts Suggestions Caveats Credits Installation pipinstallpytrends Requirements WrittenforPython3.3+ RequiresRequests,lxml,Pandas backtotop API ConnecttoGoogle frompytrends.requestimportTrendReq pytrends=TrendReq(hl='en-US',tz=360) orifyouwanttouseproxiesasyouareblockedduetoGoogleratelimit: frompytrends.requestimportTrendReq pytrends=TrendReq(hl='en-US',tz=360,timeout=(10,25),proxies=['https://34.203.233.13:80',],retries=2,backoff_factor=0.1,requests_args={'verify':False}) timeout(connect,read) Seeexplantationonthisonrequestsdocs tz TimezoneOffset ForexampleUSCSTis'360'(noteNOT-360,Googleusestimezonethisway...) proxies httpsproxiesGooglepassedONLY list['https://34.203.233.13:80','https://35.201.123.31:880',...,...] retries numberofretriestotal/connect/readallrepresentedbyonescalar backoff_factor Abackofffactortoapplybetweenattemptsafterthesecondtry(mosterrorsareresolvedimmediatelybyasecondtrywithoutadelay).urllib3willsleepfor:{backofffactor}*(2^({numberoftotalretries}-1))seconds.Ifthebackoff_factoris0.1,thensleep()willsleepfor[0.0s,0.2s,0.4s,…]betweenretries.ItwillneverbelongerthanRetry.BACKOFF_MAX.Bydefault,backoffisdisabled(setto0). requests_args Adictwithadditionalparameterstopassalongtotheunderlyingrequestslibrary,forexampleverify=FalsetoignoreSSLerrors Note:theparameterhlspecifieshostlanguageforaccessingGoogleTrends. Note:onlyhttpsproxieswillwork,andyouneedtoaddtheportnumberaftertheproxyipaddress BuildPayload kw_list=["Blockchain"] pytrends.build_payload(kw_list,cat=0,timeframe='today5-y',geo='',gprop='') Parameters kw_list Required Keywordstogetdatafor backtotop APIMethods ThefollowingAPImethodsareavailable: InterestOverTime:returnshistorical,indexeddataforwhenthekeywordwassearchedmostasshownonGoogleTrends'InterestOverTimesection. HistoricalHourlyInterest:returnshistorical,indexed,hourlydataforwhenthekeywordwassearchedmostasshownonGoogleTrends'InterestOverTimesection.ItsendsmultiplerequeststoGoogle,eachretrievingoneweekofhourlydata.Itseemslikethiswouldbetheonlywaytogethistorical,hourlydata. InterestbyRegion:returnsdataforwherethekeywordismostsearchedasshownonGoogleTrends'InterestbyRegionsection. RelatedTopics:returnsdatafortherelatedkeywordstoaprovidedkeywordshownonGoogleTrends'RelatedTopicssection. RelatedQueries:returnsdatafortherelatedkeywordstoaprovidedkeywordshownonGoogleTrends'RelatedQueriessection. TrendingSearches:returnsdataforlatesttrendingsearchesshownonGoogleTrends'TrendingSearchessection. TopCharts:returnsthedataforagiventopicshowninGoogleTrends'TopChartssection. Suggestions:returnsalistofadditionalsuggestedkeywordsthatcanbeusedtorefineatrendsearch. backtotop CommonAPIparameters ManyAPImethodsusethefollowing: kw_list keywordstogetdatafor Example['Pizza'] Uptofivetermsinalist:['Pizza','Italian','Spaghetti','Breadsticks','Sausage'] AdvancedKeywords WhenusingGoogleTrendsdashboardGooglemayprovidesuggestednarrowedsearchterms. Forexample"iron"willhaveadropdownof"IronChemicalElement,IronCross,IronMan,etc". Findtheencodedtopicbyusingtheget_suggestions()functionandchoosethemostrelevantoneforyou. Forexample:https://www.google.com/trends/explore#q=%2Fm%2F025rw19&cmpt=q "/m/025rw19"isthetopic"IronChemicalElement"tousethiswithpytrends Youcanalsousepytrends.suggestions()toautomatethis. cat Categorytonarrowresults FindavailablecategoriesbyinspectingtheurlwhenmanuallyusingGoogleTrends.Thecategorystartsaftercat=andendsbeforethenext&orviewthiswikipagecontainingallavailablecategories Forexample:"https://www.google.com/trends/explore#q=pizza&cat=71" '71'isthecategory Defaultstonocategory geo Twolettercountryabbreviation ForexampleUnitedStatesis'US' DefaultstoWorld MoredetailavailableforStates/Provincesbyspecifyingadditionalabbreviations Forexample:Alabamawouldbe'US-AL' Forexample:Englandwouldbe'GB-ENG' tz TimezoneOffset(inminutes) FormoreinformationofTimezoneOffset,viewthiswikipagecontainingaboutUCToffset ForexampleUSCSTis'360' timeframe Datetostartfrom Defaultstolast5yrs,'today5-y'. Everything'all' Specificdates,'YYYY-MM-DDYYYY-MM-DD'example'2016-12-142017-01-25' Specificdatetimes,'YYYY-MM-DDTHHYYYY-MM-DDTHH'example'2017-02-06T102017-02-12T07' NoteTimecomponentisbasedoffUTC CurrentTimeMinusTimePattern: ByMonth:'today#-m'where#isthenumberofmonthsfromthatdatetopulldatafor Forexample:'today3-m'wouldgetdatafromtodayto3monthsago NOTEGoogleusesUTCdateas'today' Worksfor1,3,12monthsonly! Daily:'now#-d'where#isthenumberofdaysfromthatdatetopulldatafor Forexample:'now7-d'wouldgetdatafromthelastweek Worksfor1,7daysonly! Hourly:'now#-H'where#isthenumberofhoursfromthatdatetopulldatafor Forexample:'now1-H'wouldgetdatafromthelasthour Worksfor1,4hoursonly! gprop WhatGooglepropertytofilterto Example'images' Defaultstowebsearches Canbeimages,news,youtubeorfroogle(forGoogleShoppingresults) backtotop InterestOverTime pytrends.interest_over_time() Returnspandas.Dataframe backtotop HistoricalHourlyInterest pytrends.get_historical_interest(kw_list,year_start=2018,month_start=1,day_start=1,hour_start=0,year_end=2018,month_end=2,day_end=1,hour_end=0,cat=0,geo='',gprop='',sleep=0) Parameters kw_list Required listofkeywordsthatyouwouldlikethehistoricaldata year_start,month_start,day_start,hour_start,year_end,month_end,day_end,hour_end thetimeperiodforwhichyouwouldlikethehistoricaldata sleep Ifyouarerate-limitedbyGoogle,youshouldsetthisparametertosomething(i.e.60)tospaceoffeachAPIcall. Returnspandas.Dataframe backtotop InterestbyRegion pytrends.interest_by_region(resolution='COUNTRY',inc_low_vol=True,inc_geo_code=False) Parameters resolution 'CITY'returnscityleveldata 'COUNTRY'returnscountryleveldata 'DMA'returnsMetroleveldata 'REGION'returnsRegionleveldata inc_low_vol True/False(includesgoogletrendsdataforlowvolumecountries/regionsaswell) inc_geo_code True/False(includesISOcodesofcountriesalongwiththenamesinthedata) Returnspandas.DataFrame backtotop RelatedTopics pytrends.related_topics() Returnsdictionaryofpandas.DataFrames backtotop RelatedQueries pytrends.related_queries() Returnsdictionaryofpandas.DataFrames backtotop TrendingSearches pytrends.trending_searches(pn='united_states')#trendingsearchesinrealtimeforUnitedStates pytrends.trending_searches(pn='japan')#Japan Returnspandas.DataFrame backtotop RealtimeSearchTrends pytrends.realtime_trending_searches(pn='US')#realtimesearchtrendsforUnitedStates pytrends.realtime_trending_searches(pn='IN')#India Returnspandas.DataFrame backtotop TopCharts pytrends.top_charts(date,hl='en-US',tz=300,geo='GLOBAL') Parameters date Required YYYYinteger Example2019fortheyear2019TopChartdata NoteGoogleremovedsupportformonthlyqueries(e.g.YYYY-MM) NoteGoogledoesnotreturndataforthecurrentyear Returnspandas.DataFrame backtotop Suggestions pytrends.suggestions(keyword) Parameters keyword Required keywordtogetsuggestionsfor Returnsdictionary backtotop Categories pytrends.categories() Returnsdictionary backtotop Caveats ThisisnotanofficialorsupportedAPI Googlemaychangeaggregationlevelforitemswithverylargeorverysmallsearchvolume RateLimitisnotpubliclyknown,letmeknowifyouhaveaconsistentestimate Oneuserreportsthat1,400sequentialrequestsofa4hourstimeframegotthemtothelimit.(Replicatedon2networks) Ithasbeentested,and60secondsofsleepbetweenrequests(successfulornot)appearstobethecorrectamountonceyoureachthelimit. ForcertainconfigurationsthedependencylibcertifirequirestheenvironmentvariableREQUESTS_CA_BUNDLEtobeexplicitlysetandexported.Thisvariablemustcontainthepathwheretheca-certificatesaresavedoraSSLError:[SSL:CERTIFICATE_VERIFY_FAILED]errorisgivenatruntime. Credits MajorJSONrevisionideastakenfrompat310'sJavaScriptlibrary https://github.com/pat310/google-trends-api ConnectingtogooglecodeheavilybasedoffStackOverflowpost http://stackoverflow.com/questions/6754709/logging-in-to-google-using-python WithsomeideaspulledfromMattReid'sGoogleTrendsAPI https://bitbucket.org/mattreid9956/google-trend-api/overview About PseudoAPIforGoogleTrends Resources Readme License Viewlicense Stars 2.5k stars Watchers 108 watching Forks 692 forks Releases Noreleasespublished Packages0 Nopackagespublished Contributors67 +56contributors Languages Python 100.0% Youcan’tperformthatactionatthistime. Yousignedinwithanothertaborwindow.Reloadtorefreshyoursession. Yousignedoutinanothertaborwindow.Reloadtorefreshyoursession.



請為這篇文章評分?