Issue
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
Solution
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)
Answered By - Vasu Kandimalla
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.