Items derived from one function are getting printed within another for loop in another function I have written some code in python to scrape some items from a webpage. There is a link (titling see more) attach to each container. If I click on that link I can reach a certain page where all the information is available. It is quite convenient to track the see more link and parse all documents from there. However, my goal is to parse the first two documents from the first page and going on to the other page (clicking on the see more button) I'll parse the rest. I have tried to do the same as I described just now. It is doing just fine. 

At this point, I'm seriously dubious whether the way I'm doing things is the right one or error-prone because I used two items from earlier page to get printed within the newly defined for loop created in the later function. It is giving me the accurate results though. Any suggestion as to what I did here is ideal or any guidance why I should not practice this will be highly appreciated.

This is the site link. This is the full script:

import requests
from urllib.parse import urljoin
from bs4 import BeautifulSoup

url = 'replace_with_the_above_link'

def glean_items(main_link):
    res = requests.get(main_link)
    soup = BeautifulSoup(res.text,"lxml")
    for item in soup.select('.course-list-item'):
        event = item.select(".lead")[0].text
        date = item.select(".date")[0].text
        link = urljoin(main_link,item.select(".pull-right a")[0]['href'])
        parse_more(event,date,link)

def parse_more(event_name,ev_date,i_link): ## notice the two items (event_name,ev_date)
    res = requests.get(i_link)
    soup = BeautifulSoup(res.text,"lxml")
    for items in soup.select('.e-loc-cost'):
        location = ' '.join([' '.join(item.text.split()) for item in items.select(".event-add")])
        cost = ' '.join([' '.join(item.text.split()) for item in items.select(".costs")])
        print(event_name,ev_date,location,cost) ##again take a look: I used those two items within this newly created for loop.

if __name__ == '__main__':
    glean_items(url)
First of all, usual things (I feel like I'm suggesting these things in most of the web-scraping related discussions):

initialize session as requests.Session() and use session.get() instead of requests.get() - this would speed things up because the underlying TCP connection will be re-used for subsequent queries to the same domain
use SoupStrainer to limit what is parsed when the &quot;soup&quot; object is initialized

And, I am not completely sure about the reliability of the .pull_right a selector. At this point, it reads that you want to follow the link that is on the right in its respective container. The position of the element on the screen may easily change with a design change. What about a selector like a[id*=ReadMore] or .more &gt; a?
Also, note that select()[0] could be replaced with select_one().
Code Style
There is not a lot of things to point out since the code is rather short and straightforward, but there are some PEP8 violations that can be addressed:

watch for the use of blank lines
you miss spaces between the function arguments
url should be named URL, since it is a &quot;constant&quot;
use a single # for comments
group imports properly

Some of the variable names could be more explicit, e.g. event_date in place of ev_date, event_link instead of i_link.
The improved code
from urllib.parse import urljoin

from bs4 import BeautifulSoup, SoupStrainer
import requests

URL = 'replace_with_the_above_link'


def glean_items(session, main_link):
    response = session.get(main_link)
    
    parse_only = SoupStrainer(class_='course-list-item')
    soup = BeautifulSoup(response.text, &quot;lxml&quot;, parse_only=parse_only)
    for item in soup.select('.course-list-item'):
        event = item.select_one(&quot;.lead&quot;).text
        date = item.select_one(&quot;.date&quot;).text
        link = urljoin(main_link, item.select_one(&quot;.pull-right a&quot;)['href'])

        parse_more(session, event, date, link)


def parse_more(session, event_name, event_date, event_link):
    response = session.get(event_link)
    
    parse_only = SoupStrainer(class_=&quot;e-loc-cost&quot;)
    soup = BeautifulSoup(response.text, &quot;lxml&quot;, parse_only=parse_only)
    for items in soup.select('.e-loc-cost'):
        location = ' '.join([' '.join(item.text.split()) for item in items.select(&quot;.event-add&quot;)])
        cost = ' '.join([' '.join(item.text.split()) for item in items.select(&quot;.costs&quot;)])
        
        print(event_name, event_date, location, cost)


if __name__ == '__main__':
    with requests.Session() as session:
        glean_items(session, URL)