Web Scrapping

In this article we will see how you can scrape any website & import its content in your python program. From there you can easily dump ...

In this article we will see how you can scrape any website & import its content in your python program. From there you can easily dump that data into any file, database or CSV. For web scrapping we will use BeautifulSoup module of python.


What is Web Scrapping?

Whenever we send request of any page suppose www.google.com web servers return raw html file. This html file is converted to webpage by browser. In this tutorial we will import this html file in our python program & save some of its data without sending it to python. This is called Web Scrapping.

 

Complete code : GitHub 


Overview of steps :

  1. Setting up the environment
  2. Get the html
  3. Parse the html
  4. HTML tree traversal
  5. Lets go

 

Related Articles : CRUD website using node & mongoose , Customize Github landing page

 

We will install requests (helps in importing any content from any website), html5lib (this will parse the data) & bs4 (it will provide different functionality on data) python libraries.

 

 In order to get HTML as string we will use requests module & parse (using BeautifulSoup) it to give tree like structure so that we can traverse over it.

 

Now use your terminal & install all the required modules by typing below code :

  1. pip install requests
  2. pip install bs4
  3. pip install html5lib

 

Create main.py import modules in the file & write URL of website which you want to scrape. Next we will get the html.


r = requests.get(url)
htmlContent = r.content

 

Then we will parse the html.

soup = BeautifulSoup(htmlContent, 'html.parser')

 

Now if you print the htmlContent you will get source code of website in console window. You can now parse html content & store it in a variable. If you print that variable you will see source code in indented manner.


Other Articles : Data Structures, LeetCode


Some commands with their functions which we have used :

  1. print(type(title))  : Print the type of title. In our case its bs4.
  2. print(type(title.string)) : Print NavigableString
  3. print(type(soup)) : Print BeautifulSoup object
  4. paras = soup.find_all('p') : Get all the paragraphs from the page. Similarly you can pass 'a' (for anchor tags), 'img' (for image)
  5. print(soup.find('p') ) : Get first para tag
  6. print(soup.find('p')['class']) : Get classes of any element in the HTML page
  7. print(soup.find_all("div", class_="rating-number")) : Find all div with class rating-number
  8. print(soup.find('div').get_text()) : Get text present inside all div
  9. print(soup.get_text()) : Get all the text of source code
  10. anchors = soup.find_all('a') : Find all anchor tags of page

Next by running loop you can get all links present in the page.

  1. for i in anchors:
         print(i.get('href')) # Get all links present on page.
  2. Now we will modify the above statement. Basically we will avoid pound signs (#) & inorder to keep all links unique we will create set. Important note : Make sure that your linkText & url variable has same URL in it.
 

 Other commands.

  • anyID = soup.find(id='anyID')
    print(anyID)                              # Prints all element associated with anyID  id.

 

COMMENTS

Nama

2fa,2,9Router,5,adsense,3,ai,38,AI,1,AI Agent,11,AI Development,7,AIRouter,1,Alat,1,Algorithms,3,Android,29,anti virus,1,Apache,4,api,4,apipedia,4,Aplikasi Android,10,apps,2,AppSheet,40,arang,1,Array,3,array formula,3,Artificial Intelligence,9,ArtificialIntelligence,1,Artikel,8,Baileys Library,1,bca,1,Belajar,1,Bengkak,1,Berita,1,Berita terkini,13,Biografi,1,Bisnis,139,Bitcoin,1,Blog,7,Blogger,34,Blogger Template,1,Blogging,2,Bootable,1,bot,1,build with ai,10,build with syahdandev,16,bun.js,1,catlang,1,Caveman AI,1,chat gpt,2,Cheat,1,Chrome,2,claude,1,Claude Code,5,cloudflare,1,Code,16,coding,12,collaboration tools,2,Competitive Coding,7,copilot,1,CPU,1,Crud,1,CSS3,2,Cursor AI,1,cybersecurity,8,Data Structures,18,Database,1,decode,1,Deep Learning,3,Desain Blogger,47,Design,3,developer,5,Developer Tools,4,Development,8,Domain Hosting,2,Download,4,dunia kerja,2,Elon Musk,4,enak,1,encode,1,excel,2,express,1,Facebook,2,fact or hoax,1,fastify,1,framebox,1,free,1,Free Course,13,Game,5,Gamers,2,gemini,2,generate with AI,3,generator,1,github,2,google,12,Google AdSense,20,Google Apps Script,25,google calendar,1,google docs,2,google drive,2,google forms,1,google mail,1,google maps,1,Google Script,3,google sheets,15,Google Webmaster Tools,1,Hardware,1,Home,1,hosting,4,Hostinger,1,HP,2,HTML,6,HTML5,2,HyperOs,1,ice cream,1,ide kreatif,2,image creator,2,Indonesia,1,Instagram,2,instant vdeo generator,1,integrator,1,Internet,9,iOS,1,IOT,2,iphone,1,IT,6,Javascript,1,JavaScript,7,js,4,Kenali,1,Keren,1,Kesehatan,14,lan,1,laragon,1,laravel,1,Leet Code,7,library,1,Linked List,4,Linux,8,llama,1,LLM,7,Machine Learning,4,malware,2,map,1,Mark Zuck,1,Marketing Tools,1,marketplace,1,Mata,1,Math,8,mbti,2,McDonald's,1,meme,1,meta,1,mfa,1,Microsoft Word,1,Minimalis,1,miscellaneous questions,1,mixue,1,Mobile Legends,4,Motherboard,1,motivasi,1,murah,1,mysql,5,Neovim,1,net use,1,Networking,1,next js,1,ngingx,1,NIK,1,NLP,1,no code,5,node js,11,nodejs,1,NodeJs,1,NPWP,1,obfuscated,1,Office,1,open ai,3,OpenAICompatible,1,Oppo,1,Parallel Space,1,pc,2,PDF Print,1,pgsql,2,Phoenix OS,1,PHP,16,phpmyadmin,2,portofolio,1,postman,3,Power Point,1,Presentation,1,price list,1,Productivity,2,Productivity Tips,1,Program Aplikasi,6,programmer,3,programming,1,Programming,1,Programming Trends,1,psikolog,4,python,5,query,1,Quesions or Answers (Quora),2,Questions or Answers (Quora),1,RAR,2,ReactJS,1,Recursion,3,Redux Toolkit,1,regex,2,Regulasi,1,Review,147,RTK,1,Rufus,1,Rumus,55,Rust Token Killer,1,Sakit,1,Samsung,1,Security,1,SEO,21,SHAREit,1,shop,1,simple apps,2,Smart City,1,smartfren,1,Smartphone,1,sms,1,Social Media,1,socket.io,2,Software,2,Software Development,4,Software Engineering,5,SoftwareEngineering,1,spesifikasi,1,SQL,1,SQL Server,1,State Management,2,Steemit,7,string,3,team IT,1,Tebak Gambar,2,Tech Trends,3,Technology,4,Teknologi,10,Teknologi Informasi,3,Telegram,3,Template Blog SEO,10,Template Blogger,1,Templates,1,terminal,1,tiktok,1,Tips,22,Tips & Trik,20,Tips Blogging,36,Tips SEO,23,Token Optimization,2,TokenSaving,1,toolkit,1,Tree,8,Trick,27,trik,3,Tulisan Lepas,1,tutorial,6,Tutorial CSS,3,Tutorial HTML,56,Tutorial JavaScript,3,Tutorial Programming,1,Twitter,2,Ubuntu,5,udemy,7,UX,8,Vibe Coding,2,vibecoding,1,VirtualBox,1,VLC Media Player,1,VSCode,2,waconsole,26,wallpaper engine,1,web dev,2,Web Development,2,Web Server,5,WebDevelopment,1,WhatsApp,14,WhatsApp Gateway,9,Widget,2,Windows,25,wordpress,4,XAMPP,7,Xiaomi,5,Yii2,1,YouTube,3,
ltr
item
Syahdan Dev Blog: Web Scrapping
Web Scrapping
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYMAAACCCAMAAACTkVQxAAABIFBMVEX///9kZGRdXV1hYWFbW1v8/PzExMTIyMhYWFja2to3c6U3dan29vaurq7v7+//1UU3eK7T09P/3E3/zj3/00M2b563t7eIiIj/2UmBgYH/3k+SkpJTU1M3e7P/yjnr6+s2aZRtbW3/5VeioqKXl5fi4uL/xjRzc3Po7/V7e3vPz8//99X/6ly3ytv/8sy7u7v/+OX/8Kv/4pL//PNsncgbbKiHobxckLz/53MmZ5r/0lP/7oT/243/0mb/wyTY4+6VuddPh7mGq80hc7Jtl76nwNbH2OhAgbaWsMn/8LX/3lX/2Dn/5Yb/78CdtMgkYI7/zylwk7L/5p7/3H9Kd53/0Vx2nLz/7XT/674UX5b/9Nv/5nz/zUr/6Zj/5KX/vw29VWLWAAAMOUlEQVR4nO2d+UObyB7AgYGEWIjikRjjJqVADm2MrVqb7npXe9ju+ur2ve6zx///XzxmBpK50EQN4SXz+cE1FIZxPsz5HbKKIpFIJBKJRCKRSCQSiUQikUgkEolEIpFIJEq9PukczDZGMVd17UnnYqapVzUd6FPtoNU66hyf7u6fQHZ3T487Ry1r0pkiKQBVVbUpdtA53v/t7OzsN8wCZG9v4e15hiwU1Gl2YBy/i0t/oGBh4Qnk3Jh07mKm28EpZYBS8OTJ6aRzFzPVDrCCuCFaoBXM9bIiYZodHL2DRX96cX4iUhDSmXQOMek5MBAp3KhPJ6wAZxfw1rtCBXNzaeaGwNgIyI/pOSh5nu95QRnd1UtjWHIcPv276LfWGW0gUtC7SCEXLFbgtfUceSQ9B5ZVKBmWoxbC3+12Gg5OQwfH+N7vRArmeucp5IIhqGgamJSD8PZdRdmwPUUp2uU0HOwO6sGeSMFK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iXA8OxUQwNCHZmzRSfk/ZPhAYOG0khG47RHFj1IG+XVfw1N1pldsdEEVsfr5Z5BSh2/P221Wqa0RyUVE3HUR6gmfbMrtYR/Dy4WuIjx4cHyREbni6MnA3twIlCmprelgYwO1vX/Zhl1A7VrreE74InYcDo/PqwDuouimQ2fUcaINj88PL66/dQxZuv11++DdsVUxTEcTMBhu3ZXUf+L+d4dnZ2tre3d0Z6/mmGHuXP8HRAIpEkgOLZhoCsfg/ulCEqeoEMyZigy5n75mtLihgzt5Z+golJ53nK4AUUOQQaJp3tKYIz0C/3OobVICU8OgkK6gSMBSnhsWEcUAqCgJLAOJh0zqeHxLYooRbIajAG+EER3yWLOuVJ53uqGHpoKkdF48QYwgN5zqTzO6UYQzPpnE47svQzgxEHVgzyg0QikUgkEolEIpFIJBKJRCKRSCQSiUQikUgkkhH5H+ifDVGuXJYRAAAAAElFTkSuQmCC
Syahdan Dev Blog
https://syahdandev.blogspot.com/2020/08/web-scrapping.html
https://syahdandev.blogspot.com/
https://syahdandev.blogspot.com/
https://syahdandev.blogspot.com/2020/08/web-scrapping.html
true
6341435550051226882
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content