I'm trying to use a value returned by one function as the argument value for another function - in this case, getting the page to open in selenium. However, outside of the function it does not recognise the value returned:
def discover(self, terms):
self.open_browser()
for term in terms:
self.search(term)
time.sleep(2)
html = BeautifulSoup(self.driver.page_source, 'lxml')
time.sleep(0.5)
#self.scroll(html)
cards = html.find_all('div', class_='styles__UserCardInformation-sc-f909fw-5 jEfkYy')
#print(cards)
time.sleep(0.5)
for card in cards:
self.open_profile(card)
self.driver.get(user_profile_url)
The user_profile_url is returned by the open_profile function, ideal to be passed through the driver.get function. However, this doesn't work.
open_profile function
def open_profile(self, card):
user = card.div.span.a.p.text
user_link_suffix = card.div.span.a['href']
user_profile_url = f'https://www.mixcloud.com{user_link_suffix}'
print(user)
return user_profile_url
CodePudding user response:
you need to assign the return value before using it
def discover(self, terms):
self.open_browser()
for term in terms:
self.search(term)
time.sleep(2)
html = BeautifulSoup(self.driver.page_source, 'lxml')
time.sleep(0.5)
#self.scroll(html)
cards = html.find_all('div', class_='styles__UserCardInformation-sc-f909fw-5 jEfkYy')
#print(cards)
time.sleep(0.5)
for card in cards:
user_profile_url = self.open_profile(card)
self.driver.get(user_profile_url)
CodePudding user response:
You can either assign the open_profile() to some variable and then pass that to get() or simply...
self.driver.get(self.open_profile(card))