Python Forum
how to make my product description fetching function generic?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to make my product description fetching function generic?
#1
Hi All,

I am fetching product description(with html tags) from a site using BeautifulSoup+Python3.6.

My code is as below-

def get_soup(url):
try:
    response = requests.get(url)
    if response.status_code == 200:
        html = response.content
        return BeautifulSoup(html, "html.parser")
except Exception as ex:
    print("error from " + url + ": " + str(ex))

def get_product_details(url):
try:
    desc_list = soup.select('p ~ ul')
    prod_details['description'] = ''.join([str(i) for i in desc_list])
    return prod_details
except Exception as ex:
    logger.warning('%s - %s', ex, url)

if __name__ == '__main__':
    print("product1 description:")
    get_product_details("http://www.aprisin.com.sg/p-748-littletikespoptunesguitar.html")
    print("product2 description:")
    get_product_details("http://www.aprisin.com.sg/p-1052-172083littletikesclassiccastle.html")
The problem with my above code is that it is not able to fetch description for some product urls.
Like in above code product2 description: is blank.Sample output-
product1 description:
<ul>
<li>Freestyle</li>
<li>Play along with 5 pre-set tunes: </li>
</ul><ul>
<li>Each string will play a note</li>
<li>Guitar has a whammy bar</li>
<li>2-in-1 volume control and power button </li>
<li>Simple and easy to use </li>
<li>Helps develop music appreciation </li>
<li>Requires 3 "AA" alkaline batteries (included)</li>
</ul>
product2 description:
So what changes I need to make here so that it may work for all types of product?
Reply


Messages In This Thread
how to make my product description fetching function generic? - by PrateekG - Jun-28-2018, 09:05 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Fetching Images from DB in Django Dexty 2 1,729 Mar-15-2024, 08:43 AM
Last Post: firn100
  All product links to products on a website MarionStorm 0 1,089 Jun-02-2022, 11:17 PM
Last Post: MarionStorm
  fetching, parsing data from Wikipedia apollo 2 3,561 May-06-2021, 08:08 PM
Last Post: snippsat
  Fetching and Parsing XML Data FalseFact 3 3,277 Apr-01-2019, 10:21 AM
Last Post: Larz60+
  My Django 2.0.6 logging is not working while product merging PrateekG 0 2,171 Jul-26-2018, 02:24 PM
Last Post: PrateekG
  Need help to get product details using BeautifulSoup+Python3.6! PrateekG 2 2,884 Jun-27-2018, 08:52 AM
Last Post: PrateekG
  Getting 'list index out of range' while fetching product details using BeautifulSoup? PrateekG 8 8,186 Jun-06-2018, 12:15 PM
Last Post: snippsat
  Unable to fetch product url using BeautifulSoup with Python3.6 PrateekG 6 4,247 Jun-05-2018, 05:49 PM
Last Post: PrateekG
  Generic If Popup Exists Close It Script digitalmatic7 1 2,489 Feb-18-2018, 07:24 AM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020