Web scraping and how to do it - somelinesforyou

Web scraping and how to do it

  • By- Admin
  • On- 10 Dec, 2019
  • Tags: Technical

"Web scraping"


Web scraping is one type to way to get data of the live site which you want from their server without any security issue, and without searching your personal details.

What are the main benefits of web scraping? 

  • You can easily use other site data in your blog portal or site without rewrite content; however, after scraping, you need to change scraping data content which you will get from another site.
  • The most important view is that you can easily raise your site organic traffic with the help of scraping data.

How people can scrape the data from a site?

Nowadays, The technical market has too many tools and programming scripts available to do it well.

Both ways are efficient to get proper details and data, but here main notable point is that mostly scraping tools are not freely available on the market, so programming is best for it, however, it's also not free for a non-tech people but it ignorable than the high price of scraping tools.

So here I would like to see a replica of the programming scraping.

  •  People can do it with many programming languages such as Node.js, PHP, JavaScript, Python(current is most popular), and many more.


Why Python is most famous for scraping?

because Python has too many strong libraries that are helping to manage scraping stability, the flexibility of coding is well.

For python scraping,

  • You can use CURL with particular headers and render URL data.
  • As a response, you can get a JSON call.
  • Otherwise, use a simple python library(beautiful soup). I show the video below about it.


If you are interested to scrap data of the web using PHP.

  • You can use CURL with accurate headers and referer URL, origin.
  • You can use simple HTML DOM, this helps to a download of DOM files and also give a guide of use.


Here I am explaining the use of HTML DOM.

 Import simple_html_dom.php file into your PHP file at the header. [ include('simple_html_dom.php'); ]


There are many different types of stream for different purposes.

// to parse a web-page

 $html = file_get_html("http://web_url"); // file_get_html("https://blah_blah.com/") 


// get data from particular location

 $html = file_get_html("index.html");

// put data a string as HTML code

 $html = str_get_html("<html><head><title>Cool HTML Parser</title></head><body><h2>PHP Simple HTML DOM Parser</h2><p>PHP Simple HTML DOM Parser is the best HTML DOM parser in any programming language.</p></body></html>


Those above codes give only page source, now you will need to handle it as per your requirements. So for it,

 foreach($html->find() as $respnse_data){ }

// find() is one kind of search function of HTML dom.

Use of find()!

  1. For tables hyperlinks, find(table a)
  2. For body inner plaintext, find(body)


For hyperlinks.

 foreach($html->find('table a') as $respnse_data){ print_r($response_data->href); }


For Plaintext.

 foreach($html->find('body') as $respnse_data){ print_r($response_data->plaintext); }


For image.

 foreach($html->find('img') as $respnse_data){ print_r($response_data->src); }


For a particular class.

 foreach($html->find('div[class=test]') as $respnse_data){ print_r($response_data->paintext); }


Leave your comment

Your comment has been sent. Thank you!
We'll never share your email with anyone else.