我尝试在一条信息中循环x次,但似乎无法使用range()或isslice。我想说循环中的代码只循环x次。
html = driver.page_source
soup = BeautifulSoup(html, 'html.parser')
x = soup.find("div", class_="object-list-items-container")
for child in x.findChildren("section", recursive=False):
if "U heeft gereageerd" in child.text:
continue
else:
house_id = child.find("div", {'class': 'ng-scope'}).get("id")
driver.find_element_by_id(house_id).click()
我读过不少关于堆栈溢出的问题,但我可能没有足够的经验来实现它。我试过几种方法,但到目前为止都没有效果。
(“reacties”是x循环所需次数的变量)
for i in range(reacties):
for child in x.findChildren("section", recursive=False):
if "U heeft gereageerd" in child.text:
continue
else:
...........
以及:
for i in range(reacties):
child= x.findChildren("section", recursive=False)
if "U heeft gereageerd" in child.text:
continue
else:
...............