How to Scrape Target store locations data from Target.com using Python?

Learn How To Extract Target store locations data From Target.com Using Python

How to Scrape Store Locations from Target.com using Python

Web data scraping is a quicker and well-organized way of getting details about the store locations or scrape locations from website rather than using time to collect information physically. This tutorial blog is for scraping store locations as well as contact data accessible on Target.com, amongst the biggest discounted store retailers in the USA.
For the tutorial blog here, our Target store locator will scrape the information for Target store locations by the provided zip code.

We can scrape the following data fields:

1. Store’s Name
2. Store’s Address
3. Week Days
4. Phone Number
5. Hours Open

Here is the screenshot of data, which will be scraped as a part of the tutorial.

data-field.jpg

There are lots of data we can extract from a store details page on Target.com like grocery and pharmacy timings however, we’ll continue with these.

Logic behind the Scraping

Create a URL of search results pages from Target.com. Let’s use the location called Clinton in New York. Here, we’ll need to make the URL manually for scraping results from the page – https://www.target.com/store-locator/find-stores?address=12901&capabilities=&concept=
Then download the HTML of search result paged with Python Requests easily when you get the URL. We utilize Python requests for downloading the whole HTML of the page.
Then save data in the JSON file.

What are Your Requirements?

Here in the Python web scraping tutorial with Python 3, we would require some packages to download and parse the HTML. Let’s see the package requirements.

Package Installation

PIP for installing the given packages using Python at ( https://pip.pypa.io/en/stable/installing/)
Use Python Requests for making requests as well as downloading HTML content for pages at (http://docs.python-requests.org/en/master/user/install)
Use Unicode CSV to handle Unicode characters within an output file. Then install that using pip and install unicodecsv.

Coding

In case, the implant given here doesn’t work, then you may click on a link given here.

Run the Web Scraper

Assume that the web scraper is given name of target.py. In case, you type a script name within command prompt together using a -h

usage: target.py [-h] zipcode

positional arguments:
zipcode Zip code

optional arguments:
-h, --help show this help message and exit

The dispute zip code is a zip code for finding the stores near any particular location.
For instance, to get all the targeted stores in as well as near Clinton in New York, then we will put the dispute as 12901 used for the zip code given here:

python target.py 12901

It will produce the JSON result file named 12901-locations.json, which would be within the similar folder of the script.
Its output file would look just like this:

{
        "County": "Clinton", 
        "Store_Name": "Plattsburgh", 
        "State": "NY", 
        "Street": "60 Smithfield Blvd", 
        "Stores_Open": [
            "Monday-Friday", 
            "Saturday", 
            "Sunday"
        ], 
        "Contact": "(518) 247-4961", 
        "City": "Plattsburgh", 
        "Country": "United States", 
        "Zipcode": "12901-2151", 
        "Timings": [
            {
                "Week Day": "Monday-Friday", 
                "Open Hours": "8:00 a.m.-10:00 p.m."
            }, 
            {
                "Week Day": "Saturday", 
                "Open Hours": "8:00 a.m.-10:00 p.m."
            }, 
            {
                "Week Day": "Sunday", 
                "Open Hours": "8:00 a.m.-9:00 p.m."
            }
        ]
    }

You can share your views about how this scraper worked for you in the comments section given below:

Limitations

The code needs to work to scrape data from Target.com for all the available zip codes using Target.com. In case, you want any professional help about scraping difficult websites or need Target.com API services, then contact us just by filling the form given below.

Locationscloud Helps You To Get Customize Dataset As Per Requirements

Contact Us