如何在python中单击/使用从Beauty Soup解析的链接

如何在python中单击/使用从Beauty Soup解析的链接,python,selenium,beautifulsoup,python-requests,Python,Selenium,Beautifulsoup,Python Requests,您好,我是python的初学者,我不知道接下来该怎么做 在使用bs4搜索特定链接后,如何与该链接交互/单击?因此,在我的脚本中,我使用bs4搜索链接,这些链接可以在网页中单击,带有特定的关键字,因此我单击正确的产品 onSale = False # Set while loop variable shoeName = 'moon' # Set keyword to look for browser = webdriver.Chrome() browser.get(r'https://ww

您好,我是python的初学者,我不知道接下来该怎么做

在使用bs4搜索特定链接后,如何与该链接交互/单击?因此,在我的脚本中,我使用bs4搜索链接,这些链接可以在网页中单击,带有特定的关键字,因此我单击正确的产品

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

一旦找到合适的链接,我如何使用它与网站互动?我是否使用selenium、urllib和or请求?谢谢

您可以使用selenium单击链接,您可以看到如何执行此操作。或者,在使用请求获取页面(忘记urllib)并使用bs4提取url后,您可以
请求。获取('your_example_url')
并再次获取结果。

感谢您的链接和回答,我非常感谢!