Search engine scraping(Redirected from Search Engine Scraping)
Search engine scraping is the process of harvesting URLs, descriptions, or other information from search engines such as Google, Bing or Yahoo. This is a specific form of screen scraping or web scraping dedicated to search engines only.
Most commonly larger search engine optimization (SEO) providers depend on regularly scraping keywords from search engines, especially Google, to monitor the competitive position of their customers' websites for relevant keywords or their indexing status.
Search engines like Google do not allow any sort of automated access to their service but from a legal point of view there is no known case or broken law.
The process of entering a website and extracting data in an automated fashion is also often called "crawling". Search engines like Google, Bing or Yahoo are getting almost all their data from automated crawling bots.
Google is the by far largest search engine  with most users in numbers as well as most revenue in creative advertisements, this makes Google the most important search engine to scrape for SEO related companies.
Google does not take legal action against scraping, likely for self-protective reasons. However Google is using a range of defensive methods that makes scraping their results a challenging task.
- Google is testing the User-Agent (Browser type) of HTTP requests and serves a different page depending on the User-Agent. Google is automatically rejecting User-Agents that seem to originate from a possible automated bot. [Part of the Google error page: Please see Google's Terms of Service posted at http://www.google.com/terms_of_service.html ] A typical example would be using the command line browser cURL, Google will directly reject to serve any pages to it while Bing is a bit more forgiving, Bing does not seem to care about User-Agents.
- Google is using a complex system of request rate limitation which is different for each Language, Country, User-Agent as well as depending on the keyword and keyword search parameters. The rate limitation can make it unpredictable when accessing a search engine automated as the behaviour patterns are not known to the outside developer or user.
- Network and IP limitations are as well part of the scraping defense systems. Search engines can not easily be tricked by changing to another IP, while using proxies are a very important part in successful scraping. The diversity and abusive history of an IP is important as well.
- Offending IPs and offending IP networks can easily be stored in a blacklist database to detect offenders much faster. The fact that most ISPs give dynamic IP addresses to customers requires to make such automated bans only temporary to not block innocent users.
- Behaviour based detection is the most difficult defense system. Search engines serve their pages to millions of users every day, this provides a large amount of behaviour information. A scraping script or bot is not behaving like a real user, aside from having non typical access times, delays and session times the keywords being harvested might be related to each other or include unusual parameters. Google for example has a very sophisticated behaviour analyzation system, possibly using deep learning software to detect unusual patterns of access. It can detect unusual activity much faster than other search engines.
- HTML markup changes, depending on the methods used to harvest the content of a website even a small change in HTML data can render a scraping tool broken until it was updated.
- General changes in detection systems. In the past years search engines have tightened their detection systems nearly month by month making it more and more difficult to reliable scrape as the developers need to experiment and adapt their code regularly.
When search engine defense thinks an access might be automated the search engine can react differently.
The first layer of defense is a captcha page where the user is prompted to verify he is a real person and not a bot or tool. Solving the captcha will create a cookie that permits access to the search engine again for a while. After about one day the captcha page is removed again.
The second layer of defense is a similar error page but without captcha, in such a case the user is completely blocked from using the search engine until the temporary block is lifted or the user changes his IP.
The third layer of defense is a longterm block of the entire network segment. Google has blocked large network blocks for months. This sort of block is likely triggered by an administrator and only happens if a scraping tool is sending a very high amount of requests.
All these forms of detection may also happen to a normal user, especially users sharing the same IP address or network class (IPV4 ranges as well as IPv6 ranges).
Methods of scraping Google, Bing or YahooEdit
To scrape a search engine successfully the two major factors are time and amount.
The more keywords a user needs to scrape and the smaller the time for the job the more difficult scraping will be and the more developed a scraping script or tool needs to be.
Scraping scripts need to overcome a few technical challenges:
- IP rotation using Proxies (proxies should be unshared and not listed in blacklists)
- Proper time management, time between keyword changes, pagination as well as correctly placed delays Effective longterm scraping rates can vary from only 3–5 requests (keywords or pages) per hour up to 100 and more per hour for each IP address / Proxy in use. The quality of IPs, methods of scraping, keywords requested and language/country requested can greatly affect the possible maximum rate.
- Correct handling of URL parameters, cookies as well as HTTP headers to emulate a user with a typical browser 
- HTML DOM parsing (extracting URLs, descriptions, ranking position, sitelinks and other relevant data from the HTML code)
- Error handling, automated reaction on captcha or block pages and other unusual responses
When developing a scraper for a search engine almost any programming language can be used but depending on performance requirements some languages will be favorable.
PHP is a commonly used language to write scraping scripts for websites or backend services, it has powerful capabilities built in (DOM parsers, libcURL) but its memory usage is typical 10 times the factor of a similar C/C++ code. Ruby on Rails as well as Python are also frequently used to automated scraping jobs. For highest performance C++ DOM parsers should be considered.
Even bash scripting can be used together with cURL as command line tool to scrape a search engine.
Tools and scriptsEdit
When developing a search engine scraper there are several existing tools and libraries available that can either be used, extended or just analyzed to learn from.
When scraping websites and services the legal part is often a big concern for companies, for web scraping it greatly depends on the country a scraping user/company is from as well as which data or website is being scraped. With many different court rulings all over the world. However, when it comes to scraping search engines the situation is different, search engines do usually not list intellectual property as they just repeat or summarize information they scraped from other websites.
The largest public known incident of a search engine being scraped happened in 2011 when Microsoft was caught scraping unknown keywords from Google for their own, rather new Bing service. () But even this incident did not result in a court case.
One possible reason might be that search engines like Google are getting almost all their data by scraping millions of public reachable websites, also without reading and accepting those terms. A legal case won by Google against Microsoft would possibly put their whole business as risk.
- "Automated queries – Search Console Help". support.google.com. Retrieved 2017-04-02.
- "Google Still World's Most Popular Search Engine By Far, But Share Of Unique Searchers Dips Slightly". searchengineland.com. 11 February 2013.
- "why would curl and wget result in a 403 forbidden?". unix.stackexchange.com.
- "Does Google know that I am using Tor Browser?". tor.stackexchange.com.
- "Google Groups". google.com.
- "My computer is sending automated queries – reCAPTCHA Help". support.google.com. Retrieved 2017-04-02.
- "Scraping Google Ranks for Fun and Profit". google-rank-checker.squabbel.com.
- "The Ultimate Guide to the Google Search Parameters". moz.com.
- "iMacros to extract google results". stackoverflow.com. Retrieved 2017-04-04.
- "Is Web Scraping Legal?". Icreon (blog).
- "Appeals court reverses hacker/troll "weev" conviction and sentence [Updated]". arstechnica.com.
- "Can Scraping Non-Infringing Content Become Copyright Infringement... Because Of How Scrapers Work?". www.techdirt.com.
- Singel, Ryan. "Google Catches Bing Copying; Microsoft Says 'So What?'". Wired.
- Scrapy Open source python framework, not dedicated to search engine scraping but regularly used as base and with a large number of users.
- Compunect scraping sourcecode - A range of well known open source PHP scraping scripts including a regularly maintained Google Search scraper for scraping advertisements and organic resultpages.
- Justone free scraping scripts - Information about Google scraping as well as open source PHP scripts (last updated mid 2016)
- Scraping.Services source code - Python and PHP open source classes for a 3rd party scraping API. (updated January 2017, free for private use)
- PHP Simpledom A widespread open source PHP DOM parser to interpret HTML code into variables.