Hi i have the following in python
#Searching for company
varA = soup.find(Microsoft)
#Finding the <a> tag which contains href
#{<a data-deptmodal="true" href="https://someURL BASED ON COMPANY NAME">TEXT BASED ON COMPANY NAME</a>}
button = org.find_previous('a')
driver.find_element_by_tag_name(button).click()
and i get an error like
TypeError: Object of type 'Tag' is not JSON serializable
How do I make the webdriver click on my href after i get the soup please note that my href changes everytime i change the company name.
答案 0 :(得分:1)
要添加到现有注释中,BeautifulSoup
是一个 HTML解析器,它可以帮助您从HTML中提取数据,它不会以任何方式与页面进行交互-它不能,例如,单击链接。
如果需要在浏览器中单击链接,请通过selenium
进行操作。在您的情况下,.find_element_by_link_text()
(或.find_element_by_partial_link_text()
)定位器非常适合此问题:
driver.find_element_by_link_text("Microsoft")