Search code examples
pythonloopsnested-loopsdata-mining

Why in nested loops in python all the elements I call from the list are not looped?


city= { "adana": ["aladag"]}
for j in city:
    for k in city[j]:
        for i in range(0,100,20):
            driver.get("https://www.sahibinden.com/satilik-daire/"+j+"-"+k+"?pagingOffset={0}".format(i))    
            item_titles = driver.find_elements(By.XPATH,'//*[@id="searchResultsTable"]/tbody/tr[*]/td[2]/a[1]')
            for link in item_titles:
                try:
                    link.click()
                    item_title = driver.find_elements(By.XPATH,'//*[@id="classifiedDetail"]/div/div[1]/h1')
                    item_prices = driver.find_elements(By.XPATH,'//*[@id="classifiedDetail"]/div/div[2]/div[2]/h3')
                    item_neighbour = driver.find_elements(By.XPATH,'//*[@id="classifiedDetail"]/div/div[2]/div[2]/h2/a[3]')
                    item_date = driver.find_elements(By.XPATH,'//*[@id="classifiedDetail"]/div/div[2]/div[2]/ul/li[2]/span')
                    item_m = driver.find_elements(By.XPATH,'//*[@id="classifiedDetail"]/div/div[2]/div[2]/ul/li[5]/span')
                    
                    for title in item_title:
                        if title !="":    
                            titles_list.append(title.text)                          
                            
                    for prices in item_prices:
                        if prices !="":
                            prices_list.append(prices.text)                   
                    
                    for neighbour in item_neighbour:
                        if neighbour !="":
                            neighbourhood_list.append(neighbour.text)        
                            
                    for dat in item_date:
                        if dat !="":
                            date_list.append(dat.text)         
                            
                    for m in item_m:
                        if m !="":
                            m_list.append(m.text)
                    driver.execute_script("window.history.go(-1)")
  
                except Exception:
                    pass

I tried with a while loop but still couldn't get the result I wanted. At first I thought I wasn't getting all the postings, but I guess the real problem is in the loops because I wrote multiple nested loops, but I couldn't find exactly where. I would be glad if you help.

(Edited) I tried print(e) and this is the result

(No symbol) [0x00B637D3]
(No symbol) [0x00AF8B81]
(No symbol) [0x009FB36D]
(No symbol) [0x009FE0FB]
(No symbol) [0x009FDFD0]
(No symbol) [0x009FE250]
(No symbol) [0x00A2F0C9]
(No symbol) [0x00A230ED]
(No symbol) [0x00A4B41C]
(No symbol) [0x00A22B96]
(No symbol) [0x00A4B774]
(No symbol) [0x00A61215]
(No symbol) [0x00A4B216]
(No symbol) [0x00A20D97]
(No symbol) [0x00A2253D]
GetHandleVerifier [0x00DDABF2+2510930]
GetHandleVerifier [0x00E08EC1+2700065]
GetHandleVerifier [0x00E0C86C+2714828]
GetHandleVerifier [0x00C13480+645344]
(No symbol) [0x00B00FD2]
(No symbol) [0x00B06C68]
(No symbol) [0x00B06D4B]
(No symbol) [0x00B10D6B]
BaseThreadInitThunk [0x76D27D69+25]
RtlInitializeExceptionChain [0x77CDBB9B+107]
RtlClearBits [0x77CDBB1F+191]


Solution

  • If you don't know where the bug.

    You should print your execpt error like:

    try:
        # to do...
    
    except Exception as e:
        print(e)