How to Order Pizza, Using Code

By just running a few lines of code, I made the process of ordering pizza even easier

Christopher Zita
Dec 3, 2020 · 5 min read
Image for post
Image for post
Photo by Aurelien Theobald from Unsplash

First of all I know what you’re thinking, why create a program that orders pizza for you when you can just do it on the phone or the internet. Well sir or madam… you are absolutely correct! It’s just I’m not a good enough programmer yet to code a robot to brush my teeth or comb my hair, so ordering pizza is the best I can do. And if you’re like me and want to make the process of ordering pizza even easier, then let’s learn how to order a pizza using code.

The place the pizza will be ordered is from Pizza Nova, because it’s my favorite pizza chain (please do not attack me in the comments for this), and we’re going to code it using Web Scraping in Python.

Did you know what your reading right now is data. It may just seem like a few words to you but on the back end everything you read online is data that can be taken, picked apart, and manipulated with. Simplified this is what Web Scraping is. Web Scrapers go through the code that was created to make a website (HTML code) and take the data they want. Using Web Scraping we can also interact with webpages to click buttons, send text to input boxes, and self-scroll. This is exactly how we will use Web Scraping to go through Pizza Nova’s website and order a custom made pizza.

Ordering The Pizza

In steps I’m going to show you how I navigate the website through code to order a custom made pizza for delivery.

Each step will have a short video at the end to display what the code is doing on the site.

1. Opening The Pizza Nova Website

When you first open the website a popup opens with an input box that asks for your city. To input my city using code I need to find the location of this input box on the website and then send text to it.

Everything on any given website can be located through a selector called Xpath. So my code will find the Xpath of the input box, and then sends the text I want into it which is my city Mississauga.

#Finds the exact location of the input box
city_input_box = driver.find_element_by_xpath('/html/body/div[8]/div/div/div/div/form[2]/fieldset[1]/input')
#Sends the text Mississauga (my city) into the input box

Next we want to write some code that clicks on the create your own tab and selects pizza. The process is basically the same as above, as we will find the location of the create your own tab using Xpath, and use a function called click(), that will click on the tab and select pizza.

#Clicks on the create your own tab
create_your_own = driver.find_element_by_xpath('//*[@id="menu-item-35"]').click()
#Selects pizza
pizza = driver.find_element_by_xpath('//*[@id="pizza-builder-selector"]/div/div[1]').click()

The video below displays exactly what our code does in this step. Also take note of how fast our code performs each action on the site.

2. Making The Pizza

There are 5 sections we need to decide on to make our custom pizza. We need to decide on…

  1. Size
  2. Dough
  3. Crust
  4. Toppings
  5. Well Done or Regular

Each of these sections have their own tab on the webpage. Using the same process as above, we will find the location of these tabs using Xpath, click on them, and then select the option for each section that we want.

Personally my favorite pizza is medium in size with whole wheat dough, thick crust, grilled chicken, green peppers, sliced tomatoes as toppings, and it’s well done. The video below shows our code selecting these options in all 5 sections.

3. Checkout

Now that our pizza is built, we need to checkout and actually order it. So the next thing our code will do is find the Xpath of the add to order button, clicks it, then clicks the checkout button by finding it’s Xpath.

When this is done we will be on the checkout page where we need to put all of our personal information so they know who to deliver the pizza to and where.

All these details like first name, e-mail address, street name, postal cord, are all given through input boxes. So like we did in step 1, we will find the location of these input boxes by finding their Xpath, and then use a function called send_keys to send specific text into these boxes.

When that is done our code will then press the continue button to go to the next page where we select the payment option. Our code will select debit and then press the continue button again to finish the order.

Note: Inputted details in the video below are made up except for where I had to put real info, but those are blurred for my own protection.

Final Result

After coding up the 3rd step, we are now done and have officially ordered a pizza using nothing but a few lines of code.

To show you the entire process in full, the video below will start with me running my code in Python, and will then go through all 3 steps above and order the pizza.

And as you can see from the photo below our code worked and our custom made pizza has been delivered.

Image for post
Image for post

Learn More About Web Scraping

If you have questions and/or are interested in learning more about Web Scraping and what it can do, I’ll leave a link to a course I made that discusses Web Scraping basics, methodologies, and approaches that can help apply to your own personal projects.

Analytics Vidhya is a community of Analytics and Data…

By Analytics Vidhya

Latest news from Analytics Vidhya on our Hackathons and some of our best articles! Take a look

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Christopher Zita

Written by

Okay programmer who uses code to solve real world problems | Clean Code Z:

Analytics Vidhya

Analytics Vidhya is a community of Analytics and Data Science professionals. We are building the next-gen data science ecosystem

Christopher Zita

Written by

Okay programmer who uses code to solve real world problems | Clean Code Z:

Analytics Vidhya

Analytics Vidhya is a community of Analytics and Data Science professionals. We are building the next-gen data science ecosystem

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store