venomnert

venomnert

Scraping Google search result?

Context:

I am trying to dynamically make google search requests. However, it seems like google doesn’t offer an API for it. So my next approach is to use httpoison to make a google search via query parameter and parse through the results.

Problem:

However, I am running to a problem in which google doesn’t recognize my httpoison request as a legitimate request.

Question:

  • Have any of you guys/gals worked with google search?
  • How can I send a legitimate request via HTTPoison?

Most Liked

Phillipp

Phillipp

I can’t tell you exactly what you need to include, but here is a good approach to find out what you need:

  1. Make a manual request via your browser and record it using the devtools. Make sure you are in incognito mode so you don’t have any session data.

  2. Recreate the request, including all the headers and parameters using a HTTP tool, e.g. Postman.

  3. If step 2 works, then start to remove some headers which you think are not needed. The goal is to end up with just the stuff you need.

  4. Recreate the request using HTTPoison. It’s mostly just headers and in some cases you might also need some cookies.

The approach is pretty simple. It’s basically just emulating a real person. Have a look at headers like User-Agent, Accept, etc. Some sites try to be fancy and use those to detect crawlers.

If, for some reason, you need a cookie. Then figure out where and how the cookie is set. This means, you might end up with an extra request to obtain a cookie which you then use for the following requests.

Phillipp

Phillipp

Or use the cURL command to import into Postman :smiley: Fiddling around with a cURL command that contains headers and cookies is pretty awful :smiley:

hubertlepicki

hubertlepicki

Just to help you with some future problems, there are more that you probably don’t expect. Let me list them below:

  1. This goes against Google’s TOS. You can be in legally not great position if you do that. I’m not saying Google will actually come after you but you have to be aware that this is not valid usage of the service, from Google’s point of view.

  2. They not only say this is a violation and not do anything about it, but they will actively detect and block you from scraping search results. Google builds profiles of all browsers / users with cookies and also IP addresses, and it will record these, do some matching behind the scenes and figure out that there is a suspicious browser, coming from a suspicious IP address, and will do several things: first, they will present you with a captcha to make sure “you are not a robot”. They can also block you even if you keep solving the captcha, effectively blocking off the IP address from Google’s services. You will have to rotate the IP addresses on regular basis and build browsers’ “human-like” behavior pattern to prevent being detected. You probably want to slow things down, also visit other sites, make your profile seem like a real user etc.

This is still doable, esp. if you want to do it at small scale for own usage, but at large scale it becomes expensive, risky, and you may not want to do it.

Last Post!

venomnert

venomnert

Gotcha. I was able to make the google request work using Postman and I noticed that the requested generated a cookie and token. And I wasn’t sure how I can create a token and cookie.

Where Next?

Popular in Questions Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 131117 1222
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54260 488
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31586 112
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement