কম্পিউটার

ওয়েব স্ক্র্যাপিংয়ের জন্য পাইথন সরঞ্জাম


কম্পিউটার বিজ্ঞানে ওয়েব স্ক্র্যাপিং মানে ওয়েবসাইট থেকে ডেটা বের করা। এই কৌশলটি ব্যবহার করে ওয়েবের অসংগঠিত ডেটাকে স্ট্রাকচার্ড ডেটাতে রূপান্তরিত করে।

Python3-এ সবচেয়ে সাধারণ ওয়েব স্ক্র্যাপিং টুল হল −

  • Urllib2
  • অনুরোধ
  • সুন্দর স্যুপ
  • Lxml
  • সেলেনিয়াম
  • মেকানিক্যাল স্যুপ

Urllib2 − এই টুলটি পাইথনের সাথে প্রাক-ইনস্টল করা আছে। এই মডিউলটি ইউআরএল বের করার জন্য ব্যবহার করা হয়। urlopen () ফাংশন ব্যবহার করে বিভিন্ন প্রোটোকল (FTP, HTTPetc.) ব্যবহার করে ইউআরএল নিয়ে আসা।

উদাহরণ কোড

from urllib.request import urlopenmy_html =urlopen("https://www.tutorialspoint.com/")print(my_html.read())

আউটপুট

b'\r\n \r\n

অনুরোধ − এই মডিউলটি আগে থেকে ইনস্টল করা নেই, আমাদের কমান্ড প্রম্পটে কমান্ড লাইন লিখতে হবে।অনুরোধ HTTP/1.1.

-এ অনুরোধ পাঠান

পিপ ইনস্টল করার অনুরোধ

উদাহরণ

ইমপোর্ট রিকোয়েস্ট# URLmy_req =requests.get('https://www.tutorialspoint.com/') প্রিন্ট(my_req.encoding) প্রিন্ট(my_req.status_code) print(my_req.elapsed) print(my_req.url) পান প্রিন্ট(my_req.history)print(my_req.headers['Content-Type'])

আউটপুট

UTF-82000:00:00.205727https://www.tutorialspoint.com/[]text/html; charset=UTF-8

সুন্দর স্যুপ - এটি একটি পার্সিং লাইব্রেরি যা বিভিন্ন পার্সারে ব্যবহৃত হয়। পাইথনের স্ট্যান্ডার্ড লাইব্রেরি BeautifulSoup-এর ডিফল্ট পার্সার প্রদান করে। এটি একটি পার্সার ট্রি তৈরি করে যা HTML পৃষ্ঠা থেকে ডেটা বের করতে ব্যবহৃত হয়৷

এই মডিউলটি ইনস্টল করার জন্য, আমরা কমান্ড প্রম্পটে কমান্ড লাইন লিখি।

পিপ ইনস্টল beautifulsoup4

উদাহরণ

from bs4 import BeautifulSoup# importing requestsimport requests# get URLmy_req =requests.get("https://www.tutorialspoint.com/")my_data =my_req.textmy_soup =BeautifulSoup(my_data) my_soup-এ my_link এর জন্য a'):print(my_link.get('href'))

আউটপুট

https://www.tutorialspoint.com/index.htmhttps://www.tutorialspoint.com/questions/index.phphttps://www.tutorialspoint.com/online_dev_tools.htmhttps://www.tutorialspoint.com /codingground.htmhttps://www.tutorialspoint.com/current_affairs/index.htmhttps://www.tutorialspoint.com/upsc_ias_exams.htmhttps://www.tutorialspoint.com/tutor_connect/index.phphttps://www.tutorialspoint .com/programming_examples/https://www.tutorialspoint.com/whiteboard.htmhttps://www.tutorialspoint.com/netmeeting.phphttps://www.tutorialspoint.com/articles/https://www.tutorialspoint.com /index.htmhttps://www.tutorialspoint.com/tutorialslibrary.htmhttps://www.tutorialspoint.com/videotutorials/index.htmhttps://store.tutorialspoint.comhttps://www.tutorialspoint.com/html_online_training/index .asphttps://www.tutorialspoint.com/css_online_training/index.asphttps://www.tutorialspoint.com/3d_animation_online_training/index.asphttps://www.tutorialspoint.com/swift_4_online_training/index.asphttps://www.torialspoint .com/blo ckchain_online_training/index.asphttps://www.tutorialspoint.com/reactjs_online_training/index.asphttps://www.tutorialspoint.com/tutorialslibrary.htmhttps://www.tutorialspoint.com/computer_fundamentals/index.htm tutorialspoint.com/compiler_design/index.htmhttps://www.tutorialspoint.com/operating_system/index.htmhttps://www.tutorialspoint.com/data_structures_algorithms/index.htmhttps://www.tutorialspoint.com/dbms/index. htmhttps://www.tutorialspoint.com/data_communication_computer_network/index.htmhttps://www.tutorialspoint.com/academic_tutorials.htmhttps://www.tutorialspoint.com/html/index.htmhttps://www.tutorialspoint.com/ css/index.htmhttps://www.tutorialspoint.com/javascript/index.htmhttps://www.tutorialspoint.com/php/index.htmhttps://www.tutorialspoint.com/angular4/index.htmhttps:// www.tutorialspoint.com/mysql/index.htmhttps://www.tutorialspoint.com/web_development_tutorials.htmhttps://www.tutorialspoint.com/cprogramming/index.htmhttps://www.tutorialspoint.com/cplusplus/ind ex.htmhttps://www.tutorialspoint.com/java8/index.htmhttps://www.tutorialspoint.com/python/index.htmhttps://www.tutorialspoint.com/scala/index.htmhttps://www. tutorialspoint.com/csharp/index.htmhttps://www.tutorialspoint.com/computer_programming_tutorials.htmhttps://www.tutorialspoint.com/java8/index.htmhttps://www.tutorialspoint.com/jdbc/index.htmhttps://www.tutorialspoint.com/servlets/index.htmhttps://www.tutorialspoint.com/spring/index.htmhttps://www.tutorialspoint.com/hibernate/index.htmhttps://www.tutorialspoint.com/ swing/index.htmhttps://www.tutorialspoint.com/java_technology_tutorials.htmhttps://www.tutorialspoint.com/android/index.htmhttps://www.tutorialspoint.com/swift/index.htmhttps://www. tutorialspoint.com/ios/index.htmhttps://www.tutorialspoint.com/kotlin/index.htmhttps://www.tutorialspoint.com/react_native/index.htmhttps://www.tutorialspoint.com/xamarin/index. htmhttps://www.tutorialspoint.com/mobile_development_tutorials.htmhttps://www.tutorialspoint.com/mongodb/index.htmhtt ps://www.tutorialspoint.com/plsql/index.htmhttps://www.tutorialspoint.com/sql/index.htmhttps://www.tutorialspoint.com/db2/index.htmhttps://www.tutorialspoint। com/mysql/index.htmhttps://www.tutorialspoint.com/memcached/index.htmhttps://www.tutorialspoint.com/database_tutorials.htmhttps://www.tutorialspoint.com/asp.net/index.htmhttps://www.tutorialspoint.com/entity_framework/index.htmhttps://www.tutorialspoint.com/vb.net/index.htmhttps://www.tutorialspoint.com/ms_project/index.htmhttps://www.tutorialspoint। com/excel/index.htmhttps://www.tutorialspoint.com/word/index.htmhttps://www.tutorialspoint.com/microsoft_technologies_tutorials.htmhttps://www.tutorialspoint.com/big_data_analytics/index.htmhttps:// www.tutorialspoint.com/hadoop/index.htmhttps://www.tutorialspoint.com/sas/index.htmhttps://www.tutorialspoint.com/qlikview/index.htmhttps://www.tutorialspoint.com/power_bi/ index.htmhttps://www.tutorialspoint.com/tableau/index.htmhttps://www.tutorialspoint.com/big_data_tutorials.htmhttps://ww w.tutorialspoint.com/tutorialslibrary.htmhttps://www.tutorialspoint.com/codingground.htmhttps://www.tutorialspoint.com/coding_platform_for_websites.htmhttps://www.tutorialspoint.com/developers_best_practices/index. www.tutorialspoint.com/effective_resume_writing.htmhttps://www.tutorialspoint.com/computer_glossary.htmhttps://www.tutorialspoint.com/computer_whoiswho.htmhttps://www.tutorialspoint.com/questions_and_answers.htmhttps://www.tutorialspoint.com/questions_and_answers.htm. tutorialspoint.com/multi_language_tutorials.htmhttps://itunes.apple.com/us/app/tutorials-point/id914891263?ls=1&mt=8https://play.google.com/store/apps/details?id=com। tutorialspoint.onlineviewerhttps://www.windowsphone.com/s?appid=91249671-7184-4ad6-8a5f-d11847946b09/about/index.htm/about/about_team.htm/about/about_careers.htm/priv_careers.htm/priv_careers. about/about_terms_of_use.htmhttps://www.tutorialspoint.com/articles/https://www.tutorialspoint.com/online_dev_tools.htmhttps://www.tutorialspoint.com/free_web_graphics.htmhttps://www.tutorialspoint.com /online_file_conversion.htmhttps://www.tutorialspoint.com/shared-tutorials.phphttps://www.tutorialspoint.com/netmeeting.phphttps://www.tutorialspoint.com/free_online_whiteboard.htmhttps://www.tutorialspoint.comhttps ://www.facebook.com/tutorialspointindiahttps://plus.google.com/u/0/+tutorialspointhttps://www.twitter.com/tutorialspointhttps://www.linkedin.com/company/tutorialspointhttps:// www.youtube.com/channel/UCVLbzhxVTiTLiVKeGV7WEBghttps://www.tutorialspoint.com/index.htm/about/about_privacy.htm#cookies/about/faq.htm/about/about_helping.htm/about/htactmus> 

Lxml − এটি একটি পার্সিং লাইব্রেরি, উচ্চ-কর্মক্ষমতা, উৎপাদন-মানের HTML এবং XML পার্সিং লাইব্রেরি। আমরা যদি উচ্চ-মানের, সর্বোচ্চ গতি চাই, তাহলে আমাদের এই লাইব্রেরিটি ব্যবহার করতে হবে। এটির অনেক মডিউল রয়েছে যার মাধ্যমে আমরা ওয়েব সাইট থেকে ডেটা বের করতে পারি।

ইনস্টল করার জন্য আমরা কমান্ড প্রম্পটে লিখি

পিপ ইনস্টল lxml

উদাহরণ

lxml থেকে আমদানি করুন etreemy_root_elem =etree.Element('html')etree.SubElement(my_root_elem, 'head')etree.SubElement(my_root_elem, 'title')etree.SubElement(my_root_elem, 'body') tostring(my_root_elem, pretty_print =True).decode("utf-8"))

আউটপুট

<body/></html></pre> <p>
 <strong>সেলেনিয়াম</strong> − এটি একটি স্বয়ংক্রিয় ব্রাউজার টুল, এটি ওয়েব-ড্রাইভার নামেও পরিচিত। আমরা যখন কোনো ওয়েবসাইট ব্যবহার করি, তখন আমরা লক্ষ্য করি যে কখনও কখনও আমাদের কিছু সময়ের জন্য অপেক্ষা করতে হয়, উদাহরণস্বরূপ যখন আমরা কোনো বোতামে ক্লিক করি বা পৃষ্ঠা স্ক্রোল করি, এই মুহূর্তে সেলেনিয়ামের প্রয়োজন হয়।</P> <p>
 সেলেনিয়াম ইনস্টল করার জন্য আমরা এই কমান্ডটি ব্যবহার করি</P> <p>
 পিপ ইনস্টল সেলেনিয়াম</P> <h2>উদাহরণ</h2> <pre>selenium import webdrivermy_path_to_chromedriver ='/Users/Admin/Desktop/chromedriver'my_browser =webdriver.Chrome(executable_path =my_path_to_chromedriver)my_url ='https://www.tutorials_path_to_chromedriver =' https://www.tutorialspoint(_urmy_brows.com) পূর্বে> <h2>আউটপুট</h2> <p>
 <img loading='lazy' alt='ওয়েব স্ক্র্যাপিংয়ের জন্য পাইথন সরঞ্জাম ' src="/article/uploadfiles/202204/2022040701542865.jpg" /></P> <p>
 <strong>যান্ত্রিক স্যুপ</strong> - এটি ওয়েবসাইটগুলির সাথে স্বয়ংক্রিয় মিথস্ক্রিয়া করার জন্য আরেকটি পাইথন লাইব্রেরি। এটি ব্যবহার করে আমরা স্বয়ংক্রিয়ভাবে কুকিজ সংরক্ষণ এবং পাঠাতে পারি, পুনঃনির্দেশ অনুসরণ করতে পারি এবং লিঙ্কগুলি অনুসরণ করতে এবং ফর্ম জমা দিতে পারি। এটি জাভাস্ক্রিপ্ট করে না।</P> <p>
 ইনস্টল করার জন্য আমরা নিম্নলিখিত কমান্ড ব্যবহার করতে পারি</P> <p>
 পিপ ইন্সটল মেকানিক্যাল স্যুপ</P> <h2>উদাহরণ</h2> <pre>ইমপোর্ট mechanicalsoupmy_browser =mechanicalsoup.StatefulBrowser()my_value =my_browser.open("https://www.tutorialspoint.com/")print(my_value)my_val =my_browser.get_url()print(my_val)my_va =my_browser. ("ফর্ম")মুদ্রণ(my_va)my_value1 =my_browser.get_url()print(my_value1)</pre> <br>
            </article>

            <div class="ad5">
 <script language='javascript' src='https://bd.wsxdn.com/css/ad/bd2.js'></script>

            </div>

            <section id="turn-page" class="t-over">
                <div class="f-start f-align">
                    <i><img src="https://bd.wsxdn.com/css/img/sanjiao.svg" alt=""></i>
                    <a class='LinkPrevArticle' href='https://bd.wsxdn.com/ge064y/db648w/202204/1006106443.html' >পাইথন openpyxl মডিউল ব্যবহার করে একটি এক্সেল ফাইল পড়ুন এবং লিখুন </a>          
                </div>
                <div class="f-start f-align">
                    <i><img src="https://bd.wsxdn.com/css/img/sanjiao.svg" alt=""></i>
                    <a class='LinkNextArticle' href='https://bd.wsxdn.com/ge064y/db648w/202204/1006106445.html'  >রক পেপার সিজার গেম বাস্তবায়নের জন্য পাইথন প্রোগ্রাম </a>     
                </div>
            </section>

        </div> 

        <aside class="box-r">
            <section class="box42">
                <ol>
		 <li>
                        <a href="https://bd.wsxdn.com/ge064y/db648w/202204/1006103141.html" class="f-start">
                            <span></span>
                            <p class="r-over r-over-2" title="Python-এ None Tuple চেক করুন ">Python-এ None Tuple চেক করুন </p>
                        </a>
                    </li>
 <li>
                        <a href="https://bd.wsxdn.com/ge064y/db648w/202204/1006105425.html" class="f-start">
                            <span></span>
                            <p class="r-over r-over-2" title="পাইথনে CGI কি? ">পাইথনে CGI কি? </p>
                        </a>
                    </li>
 <li>
                        <a href="https://bd.wsxdn.com/ge064y/db648w/202204/1006105762.html" class="f-start">
                            <span></span>
                            <p class="r-over r-over-2" title="স্টুজ সাজানোর জন্য পাইথন প্রোগ্রাম ">স্টুজ সাজানোর জন্য পাইথন প্রোগ্রাম </p>
                        </a>
                    </li>
 <li>
                        <a href="https://bd.wsxdn.com/ge064y/db648w/202204/1006105763.html" class="f-start">
                            <span></span>
                            <p class="r-over r-over-2" title="Eratosthenes চালনি জন্য পাইথন প্রোগ্রাম ">Eratosthenes চালনি জন্য পাইথন প্রোগ্রাম </p>
                        </a>
                    </li>
 <li>
                        <a href="https://bd.wsxdn.com/ge064y/db648w/202204/1006105766.html" class="f-start">
                            <span></span>
                            <p class="r-over r-over-2" title="QuickSort-এর জন্য পাইথন প্রোগ্রাম ">QuickSort-এর জন্য পাইথন প্রোগ্রাম </p>
                        </a>
                    </li>
 <li>
                        <a href="https://bd.wsxdn.com/ge064y/db648w/202204/1006105770.html" class="f-start">
                            <span></span>
                            <p class="r-over r-over-2" title="মার্জ সাজানোর জন্য পাইথন প্রোগ্রাম ">মার্জ সাজানোর জন্য পাইথন প্রোগ্রাম </p>
                        </a>
                    </li>
 <li>
                        <a href="https://bd.wsxdn.com/ge064y/db648w/202204/1006105935.html" class="f-start">
                            <span></span>
                            <p class="r-over r-over-2" title="স্ক্র্যাপির সাথে পাইথন ওয়েব স্ক্র্যাপিং বাস্তবায়ন করছে ">স্ক্র্যাপির সাথে পাইথন ওয়েব স্ক্র্যাপিং বাস্তবায়ন করছে </p>
                        </a>
                    </li>
 <li>
                        <a href="https://bd.wsxdn.com/ge064y/db648w/202204/1006105955.html" class="f-start">
                            <span></span>
                            <p class="r-over r-over-2" title="স্ক্র্যাপির সাথে পাইথনে ওয়েব স্ক্র্যাপিং বাস্তবায়ন করা ">স্ক্র্যাপির সাথে পাইথনে ওয়েব স্ক্র্যাপিং বাস্তবায়ন করা </p>
                        </a>
                    </li>
 <li>
                        <a href="https://bd.wsxdn.com/ge064y/db648w/202204/1006106157.html" class="f-start">
                            <span></span>
                            <p class="r-over r-over-2" title="বিউটিফুল স্যুপের সাথে পাইথনে ওয়েব স্ক্র্যাপিং বাস্তবায়ন করছেন? ">বিউটিফুল স্যুপের সাথে পাইথনে ওয়েব স্ক্র্যাপিং বাস্তবায়ন করছেন? </p>
                        </a>
                    </li>
 <li>
                        <a href="https://bd.wsxdn.com/ge064y/db648w/202204/1006106231.html" class="f-start">
                            <span></span>
                            <p class="r-over r-over-2" title="আর্টিকেল স্ক্র্যাপিং এবং কিউরেশনের জন্য পাইথন মডিউল সংবাদপত্র? ">আর্টিকেল স্ক্র্যাপিং এবং কিউরেশনের জন্য পাইথন মডিউল সংবাদপত্র? </p>
                        </a>
                    </li>
                                  


                </ol>
            </section>




        </aside>
    </section>

    

    </section>

    <section class="box13 content box44">

        <ol class="f-between">

            
<li class="ibox">
                <a href="https://bd.wsxdn.com/ge064y/db648w/202204/1006106241.html" class="i-text">
                    <p class="r-over r-over-2">পাইথন এবং স্ক্র্যাপি ব্যবহার করে ওয়েব স্ক্র্যাপিং? </p>
                </a>
            </li>
 
<li class="ibox">
                <a href="https://bd.wsxdn.com/ge064y/db648w/202204/1006106255.html" class="i-text">
                    <p class="r-over r-over-2">পাইথনে lxml ব্যবহার করে ওয়েব স্ক্র্যাপিং বাস্তবায়ন করছেন? </p>
                </a>
            </li>
 
<li class="ibox">
                <a href="https://bd.wsxdn.com/jh066c/xv643p/202210/1006136961.html" class="i-text">
                    <p class="r-over r-over-2">31 সেরা ওয়েব স্ক্র্যাপিং টুল </p>
                </a>
            </li>
 
<li class="ibox">
                <a href="https://bd.wsxdn.com/sq061l/db614v/202212/1006148987.html" class="i-text">
                    <p class="r-over r-over-2">পেশাদারদের জন্য সেরা ওয়েব ডিজাইনিং টুল</p>
                </a>
            </li>

           



        </ol>

    </section>



    <ul class="types box23 content f-start">
        <li><a class='childclass' href='https://bd.wsxdn.com/ge064y/ca644u/' target="_self">C প্রোগ্রামিং</a></li>
<li><a class='childclass' href='https://bd.wsxdn.com/ge064y/mk645f/' target="_self">C++</a></li>
<li><a class='childclass' href='https://bd.wsxdn.com/ge064y/hf646z/' target="_self">Redis</a></li>
<li><a class='childclass' href='https://bd.wsxdn.com/ge064y/fd647x/' target="_self">BASH প্রোগ্রামিং</a></li>
<li><a class='childclass' href='https://bd.wsxdn.com/ge064y/db648w/' target="_self">Python</a></li>
<li><a class='childclass' href='https://bd.wsxdn.com/ge064y/vs649n/' target="_self">Java</a></li>
<li><a class='childclass' href='https://bd.wsxdn.com/ge064y/tr650l/' target="_self">তথ্যশালা</a></li>
<li><a class='childclass' href='https://bd.wsxdn.com/ge064y/hf651z/' target="_self">HTML</a></li>
<li><a class='childclass' href='https://bd.wsxdn.com/ge064y/mj652e/' target="_self">JavaScript</a></li>
<li><a class='childclass' href='https://bd.wsxdn.com/ge064y/ki653c/' target="_self">প্রোগ্রামিং</a></li>
<li><a class='childclass' href='https://bd.wsxdn.com/ge064y/bz654t/' target="_self">CSS</a></li>
<li><a class='childclass' href='https://bd.wsxdn.com/ge064y/zx655s/' target="_self">Ruby</a></li>
<li><a class='childclass' href='https://bd.wsxdn.com/ge064y/nl656f/' target="_self">SQL</a></li>
<li><a class='childclass' href='https://bd.wsxdn.com/ge064y/sq657k/' target="_self">IOS</a></li>
<li><a class='childclass' href='https://bd.wsxdn.com/ge064y/qo658j/' target="_self">Android</a></li>
<li><a class='childclass' href='https://bd.wsxdn.com/ge064y/vt659n/' target="_self">mongodb</a></li>
<li><a class='childclass' href='https://bd.wsxdn.com/ge064y/us660m/' target="_self">MySQL</a></li>
<li><a class='childclass' href='https://bd.wsxdn.com/ge064y/by661t/' target="_self">C#</a></li>
<li><a class='childclass' href='https://bd.wsxdn.com/ge064y/mk665e/' target="_self">PHP</a></li>
<li><a class='childclass' href='https://bd.wsxdn.com/ge064y/he671z/' target="_self">SQL সার্ভার</a></li> 
    </ul>



  


    <footer>

        <section  class="msg f-center content">

           <span class="f-start">
                কপিরাইট ©
                <a href="https://bd.wsxdn.com">https://bd.wsxdn.com</a>
                সমস্ত অধিকার সংরক্ষিত
            </span>

        </section>
    </footer>

</body>
</html>