-1

Hello I'm a beginner in python and I'm confused on where to go from here

How do I interact/click with a specific link after using bs4 to search for it? So in my script I use bs4 to search through links, that can be clicked on in the the webpage, with specific keywords so I click on the right product.

onSale = False  # Set while loop variable
shoeName = 'moon'  # Set keyword to look for
browser = webdriver.Chrome()


browser.get(r'https://www.nike.com/launch/?s=upcoming')  # Get URL to scan
soup = BeautifulSoup(browser.page_source, 'html.parser')  # Convert URL to a soup object


while onSale is False:  # Create loop to keep checking inventory

for link in soup.find_all('a', class_=r'card-link d-sm-b'):
    shoeCode = str((link.get('href', None), link.get_text()))
    compareName = re.sub("[^\w]", " ", shoeCode.lower()).split()  # Takes the link and converts it into a string

    if shoeName in compareName:  # Checks to see if the keyword is used

       # Interact/Click link

    else:
        print(shoeCode)

        continue

Once the proper link has been found how do I use it to interact with the website? Do I use selenium, urllib, and or requests? Thanks!

John DeBritto
  • 141
  • 3
  • 12

1 Answers1

1

You can use selenium to click the links, you can see how to do this here. Or, after fetching the page with requests (forget urllib) and extracting urls with bs4, you can requests.get('your_example_url') it and fetch the results again.

shamilpython
  • 479
  • 1
  • 5
  • 18