2 回答
TA贡献1812条经验 获得超5个赞
您可以使用 css 选择器来执行此操作select(),它将返回预期的输出。
from bs4 import BeautifulSoup as soup
from selenium import webdriver
#grabspage and parses it through ready for picking apart
my_url = "https://www.carehome.co.uk/care_search_results.cfm/searchunitary/Tower-Hamlets"
driver = webdriver.Chrome(executable_path='C:/Users/lemonade/Documents/work/chromedriver')
driver.get(my_url)
page_s = soup(driver.page_source, features='html.parser')
containers = page_s.select("div.home-name>p>a[href]")
for container in containers:
print(container.text.strip())
输出:
Silk Court
Westport Care Home
Aspen Court Care Home
Beaumont Court
Hawthorn Green Residential and Nursing Home
Coxley House
Toby Lodge
Hotel in the Park
34/35 Huddleston Close
Approach Lodge
TA贡献1813条经验 获得超2个赞
您可以尝试以下解决方案吗:
driver.get(" https://www.carehome.co.uk/care_search_results.cfm/searchunitary/Tower-Hamlets ")
containers=WebDriverWait(driver,10).until(EC.visibility_of_all_elements_located((By.XPATH,"//div[contains(@class,'home-name')]//p//a[@href]")))
for container in containers:
print container.text
- 2 回答
- 0 关注
- 109 浏览
添加回答
举报