最近,因为一些原因,项目有希望可以通过API的方式去推送每天的百度指数信息。故此,就有了这篇文章。
首先所有人都会想到的一个办法,使用集成接口,这个虽然简单,但是却是收费的。
而且还贼贵。关键是这个数据在页面是免费可以拿到,但是到了黑心供应商这里,就奇货可居了。
还有同学会问,百度指数官方应该是有接口的啊? 为啥不用呢? 阿西吧,最坑的就是这个了,百度指数不提供任何形式的API接口。
不慌不慌,我们先抓个包看看请求把:
果不其然,随便一抓包,我们就发现了相关暴露的API。但是需要做一些预处理,比如添加Cookie头等等等。
不过好在我们解决了第一步,找到预处理的接口。
下面我们来看如何通过云函数把冗余代码做二次封装把:
1. 首先,我们需要创建一个 PHP 云函数 (PHP劝退,哈哈哈哈) https://console.cloud.tencent.com/scf/
2.其次,我们创建一个空白函数,它大致长这样
<?php function main_handler($event, $context) { $event = json_decode(json_encode($event), true); $context = json_decode(json_encode($context), true); $word = $event['queryString']['word']; //获取需要查询的关键词 $startDate = $event['queryString']['startDate']; //获取需要查询起始时间 $endDate = $event['queryString']['endDate']; //获取需要查询截至时间 $curlzb = curl_init(); curl_setopt_array($curlzb , array( CURLOPT_URL => "https://index.baidu.com/api/SearchApi/index?area=0&word=".$word."&startDate=".$startDate."&endDate=".$endDate, //输入参数 CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => array( "Cookie: BIDUPSID=B0C30AEB4CE3D; PSTM=95574; BAIDUID=1D274ED03FE39D4D1C38A4:FG=1..." // 百度的 Cookie ), )); $responsezb = curl_exec($curlzb); curl_close($curlzb); $echo_arrzb = json_decode($responsezb, true); return $echo_arrzb['data']['generalRatio'][0]; //返回 generalRatio 字段取值 } ?>
3. 我们创建一个APIGW触发器,大致长这样:
然后,我们尝试访问下:
这样,一个查询百度指数的API就算是封装好了。我们也可以上架云市场去卖钱了。哈哈哈
作为良心博主,我当然不会做这样的事情的。一个小思路,献给大家。
Thanks for your write-up. Another item is that being a photographer will involve not only difficulty in taking award-winning photographs but additionally hardships in getting the best digital camera suited to your needs and most especially situations in maintaining the caliber of your camera. It is very true and noticeable for those photography fans that are directly into capturing the particular nature’s captivating scenes — the mountains, the forests, the wild or seas. Going to these amazing places surely requires a photographic camera that can live up to the wild’s tough surroundings.
hi!,I like your writing very much! share we communicate more about your post on AOL? I need a specialist on this area to solve my problem. May be that’s you! Looking forward to see you.
Hi, i think that i saw you visited my web site thus i got here to ?go back the desire?.I am attempting to in finding things to improve my web site!I assume its good enough to make use of a few of your ideas!!
I have observed that of all sorts of insurance, medical health insurance is the most controversial because of the turmoil between the insurance plan company’s necessity to remain afloat and the user’s need to have insurance policy. Insurance companies’ commission rates on wellbeing plans are very low, as a result some providers struggle to make a profit. Thanks for the concepts you reveal through this blog.
My brother suggested I might like this blog. He was entirely right. This post actually made my day. You cann’t imagine simply how much time I had spent for this info! Thanks!
My brother suggested I might like this blog. He used to be totally right. This submit truly made my day. You cann’t believe just how much time I had spent for this information! Thank you!
Thanks for your article. It’s very unfortunate that over the last 10 years, the travel industry has had to take on terrorism, SARS, tsunamis, influenza, swine flu, along with the first ever real global downturn. Through everthing the industry has really proven to be sturdy, resilient in addition to dynamic, getting new strategies to deal with difficulty. There are generally fresh complications and the possiblility to which the marketplace must all over again adapt and react.
Thanks for your article. One other thing is that individual American states have their own personal laws which affect people, which makes it very difficult for the the legislature to come up with a different set of recommendations concerning foreclosure on home owners. The problem is that every state features own laws and regulations which may have impact in an unwanted manner when it comes to foreclosure insurance plans.
We would also like to convey that most individuals who find themselves without having health insurance are typically students, self-employed and people who are not working. More than half of those uninsured are really under the age of Thirty five. They do not sense they are in need of health insurance because they’re young as well as healthy. The income is often spent on homes, food, and entertainment. Most people that do work either complete or part time are not supplied insurance through their work so they head out without owing to the rising price of health insurance in the United States. Thanks for the strategies you discuss through this blog.
I have acquired some new things from your website about pcs. Another thing I have always thought is that computers have become an item that each residence must have for many reasons. They offer convenient ways in which to organize the home, pay bills, go shopping, study, pay attention to music and perhaps watch tv shows. An innovative strategy to complete these types of tasks is to use a notebook computer. These computers are mobile, small, strong and lightweight.
I don?t even know how I finished up right here, but I assumed this post used to be great. I do not realize who you’re however certainly you are going to a well-known blogger in case you aren’t already 😉 Cheers!
Saved as a favorite, I really like your website!
I do like the way you have presented this specific difficulty plus it really does give me some fodder for thought. Nevertheless, because of everything that I have seen, I just simply wish as other commentary pack on that folks keep on issue and not start on a tirade involving some other news du jour. Yet, thank you for this superb point and even though I do not really go along with this in totality, I value your standpoint.
I have discovered that wise real estate agents everywhere you go are getting set to FSBO ***********. They are recognizing that it’s not just placing a sign in the front yard. It’s really concerning building relationships with these vendors who someday will become consumers. So, once you give your time and effort to encouraging these suppliers go it alone : the “Law of Reciprocity” kicks in. Interesting blog post.
I needed to thank you for this fantastic read!! I absolutely loved every bit of it. I have got you book-marked to look at new stuff you post…
I absolutely love your blog.. Very nice colors & theme. Did you build this website yourself? Please reply back as I’m attempting to create my own personal website and want to learn where you got this from or just what the theme is called. Many thanks.
Normally I don’t read article on blogs, but I would like to say that this write-up very pressured me to check out and do so! Your writing style has been surprised me. Thank you, very nice article.
Excellent blog you have got here.. It’s difficult to find high quality writing like yours these days. I really appreciate individuals like you! Take care!!
Your style is so unique in comparison to other folks I’ve read stuff from. I appreciate you for posting when you have the opportunity, Guess I’ll just bookmark this blog.
I do not even understand how I finished up right here, but I thought this put up was good. I do not realize who you are however definitely you’re going to a well-known blogger when you aren’t already 😉 Cheers!
After I initially left a comment I seem to have clicked on the -Notify me when new comments are added- checkbox and from now on every time a comment is added I get 4 emails with the same comment. Is there an easy method you can remove me from that service? Thanks a lot.
I have realized that over the course of constructing a relationship with real estate owners, you’ll be able to get them to understand that, in most real estate contract, a commission rate is paid. Ultimately, FSBO sellers do not “save” the commission payment. Rather, they fight to win the commission by doing a agent’s task. In the process, they devote their money as well as time to accomplish, as best they are able to, the assignments of an adviser. Those jobs include uncovering the home by marketing, presenting the home to buyers, making a sense of buyer emergency in order to induce an offer, making arrangement for home inspections, controlling qualification check ups with the loan company, supervising fixes, and aiding the closing of the deal.
I?m not sure where you are getting your information, but great topic. I needs to spend some time learning more or understanding more. Thanks for fantastic info I was looking for this information for my mission.
I am grateful for your post. I’d really like to say that the expense of car insurance varies from one plan to another, mainly because there are so many different issues which bring about the overall cost. For example, the model and make of the car or truck will have an enormous bearing on the charge. A reliable outdated family auto will have a less expensive premium than a flashy sports car.
You really make it seem so easy with your presentation but I find this matter to be actually something that I think I would never understand. It seems too complex and very broad for me. I am looking forward for your next post, I will try to get the hang of it!
This is the right webpage for anyone who hopes to understand this topic. You understand so much its almost hard to argue with you (not that I really will need to…HaHa). You certainly put a brand new spin on a topic that’s been written about for a long time. Excellent stuff, just great.
I believe that avoiding packaged foods may be the first step for you to lose weight. They will often taste good, but processed foods contain very little vitamins and minerals, making you try to eat more just to have enough strength to get over the day. If you’re constantly having these foods, converting to whole grain products and other complex carbohydrates will make you to have more strength while eating less. Interesting blog post.
I am really inspired together with your writing skills as well as with the layout to your weblog. Is that this a paid subject or did you modify it your self? Either way keep up the excellent quality writing, it is uncommon to look a nice blog like this one nowadays..
I have been absent for some time, but now I remember why I used to love this blog. Thanks , I?ll try and check back more often. How frequently you update your site?
You need to be a part of a contest for one of the best websites on the net. I am going to recommend this site!
Pretty nice post. I just stumbled upon your blog and wished to say that I have truly enjoyed browsing your blog posts. After all I will be subscribing to your rss feed and I hope you write again soon!
It is really a great and helpful piece of information. I?m glad that you shared this helpful information with us. Please keep us informed like this. Thank you for sharing.
excellent points altogether, you just gained a brand new reader. What would you recommend in regards to your post that you made a few days ago? Any positive?
One thing I want to say is car insurance cancellation is a hated experience and if you’re doing the best things as being a driver you will not get one. Lots of people do get the notice that they’ve been officially dumped by their particular insurance company they then have to scramble to get extra insurance following a cancellation. Low-priced auto insurance rates are frequently hard to get after a cancellation. Knowing the main reasons pertaining to auto insurance termination can help drivers prevent burning off one of the most important privileges obtainable. Thanks for the concepts shared through your blog.
This is a good tip especially to those fresh to the blogosphere. Simple but very precise info… Many thanks for sharing this one. A must read post!
Way cool! Some extremely valid points! I appreciate you writing this article and also the rest of the site is extremely good.
Thanks for the thoughts you write about through this web site. In addition, many young women exactly who become pregnant do not even attempt to get health care insurance because they fear they wouldn’t qualify. Although many states right now require that insurers offer coverage despite the pre-existing conditions. Fees on these kinds of guaranteed programs are usually greater, but when considering the high cost of health care it may be a safer strategy to use to protect your financial potential.
With everything that seems to be developing throughout this area, many of your points of view are actually relatively exciting. Nevertheless, I beg your pardon, but I do not subscribe to your whole theory, all be it stimulating none the less. It appears to everybody that your commentary are not completely justified and in fact you are yourself not thoroughly confident of your point. In any event I did take pleasure in examining it.
It?s really a nice and helpful piece of info. I?m glad that you shared this useful information with us. Please keep us up to date like this. Thank you for sharing.
whoah this blog is great i love reading your posts. Keep up the great work! You know, a lot of people are hunting around for this information, you can aid them greatly.
Great write-up, I?m regular visitor of one?s web site, maintain up the excellent operate, and It is going to be a regular visitor for a long time.
you’ve a great blog here! would you like to make some invite posts on my weblog?
I am no longer positive where you’re getting your information, however great topic. I must spend a while learning much more or figuring out more. Thank you for fantastic info I was on the lookout for this info for my mission.
Wow! This can be one particular of the most useful blogs We’ve ever arrive across on this subject. Basically Great. I’m also a specialist in this topic therefore I can understand your hard work.
great put up, very informative. I’m wondering why the other specialists of this sector do not notice this. You must proceed your writing. I’m sure, you have a huge readers’ base already!
I am typically to running a blog and i really recognize your content. The article has really peaks my interest. I’m going to bookmark your web site and preserve checking for brand spanking new information.
I have learned some important matters through your blog post. One other stuff I would like to convey is that there are many games that you can buy which are designed particularly for preschool age small children. They incorporate pattern recognition, colors, pets, and models. These usually focus on familiarization instead of memorization. This will keep children engaged without having the experience like they are learning. Thanks
Together with almost everything which appears to be building within this particular subject material, all your viewpoints are generally rather stimulating. Nonetheless, I am sorry, but I do not subscribe to your whole strategy, all be it exhilarating none the less. It appears to me that your comments are actually not totally rationalized and in simple fact you are generally yourself not really wholly convinced of your argument. In any case I did appreciate looking at it.
What?s Taking place i am new to this, I stumbled upon this I have discovered It absolutely helpful and it has aided me out loads. I’m hoping to give a contribution & assist different customers like its helped me. Great job.
An interesting discussion is price comment. I think that you should write extra on this subject, it might not be a taboo topic but generally people are not enough to speak on such topics. To the next. Cheers