内部for循环重复多次。因此,当我将数据写入csv时,会得到多个数据副本。你知道吗
我使用selenium来点击我的搜索页面,并将每个页面的页面源交给BeautifulSoup,以获取我需要的值。你知道吗
我没有问题得到值,但是输出显示重复3-5次。因此我认为我的循环有问题。你知道吗
我尝试过使用BeautifulSoup对html进行更集中的搜索,以防html中有多个数据实例,但是仍然存在重复。你知道吗
count = 1
while True:
try:
soup = BeautifulSoup(driver.page_source, 'lxml')
leadFields = soup.find_all('div', class_='leadFields')
snippets = soup.find_all('div', class_="snippet ensnippet")
for l, s in zip(leadFields, snippets):
print (l.get_text(strip=True) + s.get_text(strip=True))
print(count)
count+=1
nextBtn = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'a.nextItem')))
action = webdriver.common.action_chains.ActionChains(driver)
action.move_to_element(nextBtn)
action.click(nextBtn).perform()
except TimeoutException:
break
添加
下一次点击后。你知道吗
另外,如果将来有人看到这一点,不要使用TimeoutException来打破一个临时的循环。你知道吗
在评论中大声向pcalkins寻求帮助。你知道吗
相关问题 更多 >
编程相关推荐