Lusian
Lusian

Reputation: 653

How to search and store data from a website?

I have a list of products that I would like to search in the following website bb farma . Ideally when inserting a product the search comes out with a list of medicines in a table as in the picture below:the following is an example of a search of the product: "Actimmune" Now, the aim is to make a search in Python (with BeautifulSoup I guess) for each product I have stored in a list and save the number called ATC in the table if the search is successful (e.g. with a try and an except). The html when inspecting the page is the following: Inspector

Alternatively, maybe I could parse the table tab directly.

Thanks a lot

Upvotes: 0

Views: 70

Answers (1)

stackz
stackz

Reputation: 84

url = 'Whatever URL'

def get_list():
    s = BeautifulSoup(url, 'lxml')
    med_tags = s.findAll('td', 'class=small')

    med_list = []
    for med in med_tags:
        try:
            whatever = med.find('a').get('href')
            med_list.append({
                'whatever med': whatever
            })
        except:
            print('Something did not work')

Upvotes: 0

Related Questions