试图像这样滚动网页,并抓取他们的公司名称和描述。我无法破解网页上滚动达到停滞点后出现的"加载更多"选项。我如何穿透"加载更多"并将内容存储在列表或df中,以便稍后解析?
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.cloudstack.org/")
time.sleep(2)
scroll_pause_time = 1
screen_height = driver.execute_script("return window.screen.height;")
i = 1
while True:
driver.execute_script("window.scrollTo(0, {screen_height}*{i});".format(screen_height=screen_height, i=i))
i += 1
time.sleep(scroll_pause_time)
scroll_height = driver.execute_script("return document.body.scrollHeight;")
if (screen_height) * i > scroll_height:
break
html_source = driver.page_source
data = html_source.encode('utf-8')
我试着用这个点击加载更多,但我遇到了";ElementNotInteractiableException";之后。
load_more = driver.find_elements_by_class_name("next-selector")
if load_more:
load_more[0].click()
帮助我但从未解决问题的文档总体
你为什么不试着勉强通过
https://www.cloudtango.org/list/?page=1
存在可以根据需要改变的CCD_ 1自变量。
还有其他论点,如:
country=&服务=&partner=&locality=&postal_town=&administrative_area_level_1=&administrative_area_level2=&administrative_area_level_3=&自动完成=&companyname=&head_office=&coordenades_lat=&coordenades_lang=&orderby=&订单=
运行loop
直到需要的页面,刮取页面并根据需要保存。没有超过200页,但
这是演示代码:
driver = webdriver.Chrome()
i=0
while True:
driver.get(f"https://www.cloudtango.org/list/?page={i}")
i+=1
if driver.title!="Where IT seekers find Cloud Service Providers - Cloudtango":
break
我们在循环时使用无穷大,但每次都检查标题。当我们到达终点时,那个无限循环将被打破。