Im not really sure what your current code is. Often if you are obtaining sub-url its best to clean the code up to not get confused.
Now you can list ul's li's via ul.find_all('li') and just go through the list of li tags. Or if you need to you can go through them one by one via find_next_sibling() to get the next li tag such as
so if you did li2.find_next_sibling().find_next_sibling() it would actually be the ad class. OR if you did find_all it would be the 4th index of li tags
EDIT:
if you just wanted to get a list of li tags with *sold* then you can use regex
'sold' would have to be the keyword as everything else changes. (if your trying to get them all). IF your trying to get only even classes then swap sold for even in regex
Quote:In the link with the houses sold " http://www.funda.nl/nl/koop/verkocht/rotterdam/p1 " is each property listed under a different nameThere are a couple ways. The root search for that is going to be
(even/uneven and the name of the real estate broker (often "nvm" but can also be another one)
ul = soup.find('ul', {'class':'object-list'})
Now you can list ul's li's via ul.find_all('li') and just go through the list of li tags. Or if you need to you can go through them one by one via find_next_sibling() to get the next li tag such as
from bs4 import BeautifulSoup import requests url = 'http://www.funda.nl/koop/verkocht/rotterdam/p1/' req = requests.get(url) soup = BeautifulSoup(req.text, 'html.parser') ul = soup.find('ul', {'class':'object-list'}) print(ul.li) #first li ;even nvm sold class li2 = ul.li.find_next_sibling() print(li2) #second li; odd nvm sold classul.li is pretty much ul.find('li')
so if you did li2.find_next_sibling().find_next_sibling() it would actually be the ad class. OR if you did find_all it would be the 4th index of li tags
EDIT:
if you just wanted to get a list of li tags with *sold* then you can use regex
li_sold = ul.find_all('li',class_=re.compile('sold'))Here this will grab everything except the ad class one.
'sold' would have to be the keyword as everything else changes. (if your trying to get them all). IF your trying to get only even classes then swap sold for even in regex
Recommended Tutorials: