mardi 19 juillet 2016

I am trying to use python and store the href element from in a list

I am trying to store the href elements in a list but have a bit of trouble due to my limited knowledge of python.

import requests, bs4

url = 'https://www.hellopeter.com/spar?page=2'
response = requests.get(url)
html = response.content

soup = bs4.BeautifulSoup(html, "lxml")

url_list = []
for detail in soup.findAll('div', attrs = {'class':'col-xs-12 review-post'}):
    for Review in detail.findAll('a', attrs = {'class':'btn btn-custom-2 btn-full-review'}):
        url_list = url_list.append(Review['href'])

I'm not sure what other alternatives there are to this, but I have been searching for a while.

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire