Categories
Development

Scrape text, parse it with BeautifulSoup and save it as Pandas data frame

We want to share with you how to scrape text and store it as Pandas data frame using BeautifulSoup (Python). The code below works to store html li items in the ‘engine, ‘trans’, ‘colour’ and ‘interior’ columns.

from bs4 import BeautifulSoup
import pandas as pd
import requests

main_url = "https://www.example.com/"

def getAndParseURL(url):
    result = requests.get(url)
    soup = BeautifulSoup(result.text, 'html.parser')
    return(soup)

soup = getAndParseURL(main_url) 
ul = soup.select('ul[class="list-inline lot-breakdown-list"] li', recursive=True)
lis_e = []
for li in ul:
    lis = []
    lis.append(li.contents[1])
    lis_e.extend(lis)

engine.append(lis_e[0])
trans.append(lis_e[1])
colour.append(lis_e[2])
interior.append(lis_e[3])

scraped_data = pd.DataFrame({'engine': engine, 
'transmission': trans, 'colour': colour,
'interior': interior})
By default, Beautiful Soup searches through all of the child elements. So, setting recursive = False (line 13) will restrict the search to the first found element and its child only.

The code was provided by Ahmed Soliman.

Categories
Review

What is a Web Crawler and how does it work?

Nowadays, when having some questions, it almost comes naturally for us to just type it in a search bar and get helpful answers. But we rarely wonder how all that information is available and how it appears as soon as we start typing. Search engines provide easy access to information, but web crawling/scraping tools who are not so much known players have a crucial role in wrapping up online content. Over the years, these tools have become a true game-changer in many businesses including e-commerce. So, if you are still unfamiliar with it, keep reading to learn more.

Categories
Review

Price2Spy Web Crawling Service for the Competitors Price Scraping

The number of companies, which use web crawler, is growing rapidly due to the current competitive market conditions. As a result, the number of companies that offer this service is growing day by day. Since the purpose of web crawler varies on a case to case basis, here is a more detailed explanation of how it Price2Spy works.