[PYTHON] You will be an engineer in 100 days ――Day 70 ――Programming ――About scraping

Click here until yesterday

You will become an engineer in 100 days --Day 66 --Programming --About natural language processing

You will become an engineer in 100 days --Day 63 --Programming --Probability 1

You will become an engineer in 100 days-Day 59-Programming-Algorithms

You will become an engineer in 100 days --- Day 53 --Git --About Git

You will become an engineer in 100 days --Day 42 --Cloud --About cloud services

You will become an engineer in 100 days --Day 36 --Database --About the database

You will be an engineer in 100 days-Day 24-Python-Basics of Python language 1

You will become an engineer in 100 days --Day 18 --Javascript --JavaScript basics 1

You will become an engineer in 100 days --Day 14 --CSS --CSS Basics 1

You will become an engineer in 100 days --Day 6 --HTML --HTML basics 1

This time is about scraping.

What is scraping?

What is scraping?

Scraping is a technology to acquire data from websites.

Scraping itself can be done in various languages.

Knowledge required for scraping

Roughly speaking, it is useful to have this knowledge.

** Communication mechanism ** Communication is required to obtain information from the WEB. It is necessary to suppress the HTTP communication mechanism that is the basis of the Internet.

HTML、Javascript、CSS The website consists of HTML, Javascript and CSS. It is necessary to suppress the mechanism of the components in the site.

** Full-text search and regular expression match ** When we get information from our website, we extract only the information we need.

In doing so, you need to determine if you have the information you need and if it matches the information you need. Knowledge of regular expressions is required to judge the condition.

** Programming language ** How to access websites and perform parsing efficiently Knowledge of programming in general and knowledge of the characteristics of programming languages are required.

Library There are usually tools (libraries) for scraping in any programming language. Creating a program from scratch is inefficient and requires learning how to use the library.

** Data mining algorithm ** Knowledge of data analysis is required to acquire information and efficiently output only the necessary parts.

** DOM analysis ** The DOM (Document Object model) is a standard specification for manipulating XML documents. Allows programming languages to manipulate elements and text in XML documents. The DOM is a method of reading an entire XML document and parsing every element in the document as a tree-structured node.

Scraping requires knowledge of the DOM.

** HTML parser (parse) ** Extracting only the text part of HTML or extracting the content of a specific tag

Internet security

Due to the convenience of accessing the website and acquiring information, security issues are inevitable.

If you use it incorrectly, you may give the site a presence or be arrested. You have to be careful.

Scraping is a useful technique, but you should be aware of the following:

** Violation of Terms of Service ** When the terms of use on the website of another person state that "scraping is prohibited" Scraping may violate the Terms of Service and may result in claims for damages.

However, the following measures are required for the terms of use to take effect with the user. Show the terms of use to the user and have them click consent to start the transaction.

If you want to scrape content that anyone can see without having to register as a member It is possible that the above terms of use will not be violated, but please note that the law changes daily.

Also, for scraping sites to restrict access to the crawler website If you crawl while measures (such as robot.txt) have been taken, you may be a civil law tort.

Copyright Since the amount of content acquired by scraping is enormous, it is not realistic to obtain consent for each content.

Therefore, as an exception, it seems that copying for information analysis is permitted without the consent of the copyright holder (Article 47-7 of the Copyright Law).

The act of transferring the collected content to another person (including online distribution) by scraping is considered a violation of copyright law.

If the content has originality, it is protected as a "literary work" under copyright law.

Copying such content or storing it on your company's server is a copyright infringement without the consent of the copyright holder.

** Counterfeit business disruption ** You will access the website at regular intervals, but if the intervals become shorter, The load on the server of the site becomes heavy, which may interfere with normal site operation.

In such a case, it is assumed that it interfered with the business of the site operator. There is a possibility that a crime of obstructing counterfeit business will be established (Article 233 of the Penal Code).

Okazaki Municipal Central Library Case

Around March 2010, from citizens to the collection search system on the Okazaki Municipal Library website
It seems that there was a complaint that I could not connect
After that, it became difficult to browse the website one after another.

On April 15, the same year, the library was receiving annoying access.
A man who submitted a damage report to the Aichi Prefectural Police Okazaki Station and was accessing it on May 25
Assuming that you intentionally sent a high-frequency request to the collection search system
He was arrested on suspicion of obstructing false accounting.

There is no illegality in the crawler created by men There was a problem with the library's collection search system.

However, the website of Okazaki Municipal Central Library is an expert as a local government site. Because it was unimaginably vulnerable This is a combination of the negligence of the municipalities and the ignorance of the person in charge.

Originally, the local government, which was poorly operated, is bad. This may not be the case by law.

Municipal and national infrastructure is very childish and often not properly operated. It may not be preferable as a scraping target. Be careful when scraping.

Other notes

. ʻIt is a violation of the Terms of Service to web scrape and crawling Amazon product pages. Is there a legal problem? ``

Acts that put a load on the server of the other party may correspond to business interruption such as counterfeit business interruption or computer damage.

It is necessary to take precautions such as performing the next processing after receiving a response.

Also, since the page is duplicated, there may be a problem of copyright infringement if it exceeds the scope of private reproduction. You need to keep it within the scope of your own browsing and data analysis purposes.

. ʻCreate a tool for web scraping and crawling Amazon product pages Is it a violation of the Terms of Service to distribute and sell? Is there any legal problem? It depends on how you write the terms of use, but if only the use of the tool is prohibited I think that the act of using the tool after receiving the distribution violates the rules. ``

Depending on how it is used, it may be an aide to business interruption or copyright infringement.

Summary

First of all, let's suppress the precautions before scraping. If you run the code suddenly, it may be difficult.

30 days until you become an engineer

Author information

Otsu py's HP: http://www.otupy.net/

Youtube: https://www.youtube.com/channel/UCaT7xpeq8n1G_HcJKKSOXMw

Twitter: https://twitter.com/otupython

Recommended Posts

You will be an engineer in 100 days ――Day 71 ――Programming ――About scraping 2
You will be an engineer in 100 days ――Day 74 ――Programming ――About scraping 5
You will be an engineer in 100 days ――Day 73 ――Programming ――About scraping 4
You will be an engineer in 100 days ――Day 75 ――Programming ――About scraping 6
You will be an engineer in 100 days ――Day 70 ――Programming ――About scraping
You will be an engineer in 100 days ――Day 61 ――Programming ――About exploration
You will be an engineer in 100 days --Day 68 --Programming --About TF-IDF
You will be an engineer in 100 days ――Day 81 ――Programming ――About machine learning 6
You will be an engineer in 100 days ――Day 82 ――Programming ――About machine learning 7
You will be an engineer in 100 days ――Day 79 ――Programming ――About machine learning 4
You will be an engineer in 100 days ――Day 76 ――Programming ――About machine learning
You will be an engineer in 100 days ――Day 80 ――Programming ――About machine learning 5
You will be an engineer in 100 days ――Day 78 ――Programming ――About machine learning 3
You will be an engineer in 100 days ――Day 83 ――Programming ――About machine learning 8
You will be an engineer in 100 days ――Day 77 ――Programming ――About machine learning 2
You will be an engineer in 100 days ――Day 85 ――Programming ――About machine learning 10
You will be an engineer in 100 days --Day 63 --Programming --Probability 1
You will be an engineer in 100 days --Day 65 --Programming --Probability 3
You will be an engineer in 100 days --Day 64 --Programming --Probability 2
You will be an engineer in 100 days --Day 86 --Database --About Hadoop
You will be an engineer in 100 days ――Day 60 ――Programming ――About data structure and sorting algorithm
You will be an engineer in 100 days --Day 27 --Python --Python Exercise 1
You will be an engineer in 100 days --Day 34 --Python --Python Exercise 3
You will be an engineer in 100 days --Day 31 --Python --Python Exercise 2
You become an engineer in 100 days ――Day 67 ――Programming ――About morphological analysis
You become an engineer in 100 days ――Day 66 ――Programming ――About natural language processing
You will be an engineer in 100 days ――Day 24 ―― Python ―― Basics of Python language 1
You will be an engineer in 100 days ――Day 25 ―― Python ―― Basics of Python language 2
You will be an engineer in 100 days --Day 29 --Python --Basics of the Python language 5
You will be an engineer in 100 days --Day 33 --Python --Basics of the Python language 8
You will be an engineer in 100 days --Day 26 --Python --Basics of the Python language 3
You will be an engineer in 100 days --Day 35 --Python --What you can do with Python
You will be an engineer in 100 days --Day 32 --Python --Basics of the Python language 7
You will be an engineer in 100 days --Day 28 --Python --Basics of the Python language 4
When you get an error in python scraping (requests)
You have to be careful about the commands you use every day in the production environment.
What beginners think about programming in 2016