Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用selenium和python自动访问下一页_Python_Html_Selenium Webdriver_Beautifulsoup_Selenium Chromedriver - Fatal编程技术网

使用selenium和python自动访问下一页

使用selenium和python自动访问下一页,python,html,selenium-webdriver,beautifulsoup,selenium-chromedriver,Python,Html,Selenium Webdriver,Beautifulsoup,Selenium Chromedriver,我目前正在编写一个python selenium脚本,以浏览“Likibu.com”,它是一个提供短期住宿的网站,如Airbnb、预订。。。我已经成功地获得了第一页中存在的所有数据,并将它们保存在csv文件中,但问题是有37页,我还想废弃这些页中存在的数据。我按如下方式管理此代码: driver.get("https://www.likibu.com/") page = driver.page_source soup = BeautifulSoup(page, "lxml") driver.ge

我目前正在编写一个python selenium脚本,以浏览“Likibu.com”,它是一个提供短期住宿的网站,如Airbnb、预订。。。我已经成功地获得了第一页中存在的所有数据,并将它们保存在csv文件中,但问题是有37页,我还想废弃这些页中存在的数据。我按如下方式管理此代码:

driver.get("https://www.likibu.com/")
page = driver.page_source
soup = BeautifulSoup(page, "lxml")
driver.get("https://www.likibu.com/{0}".format(soup.find(rel=re.compile("nofollow")).attrs["href"]))
您可以在此处找到该网页的源代码:


任何时候,当你要删除多个页面时,你必须弄清楚url是如何变化的。就你而言:

root = 'https://www.likibu.com/fr/search/39yrzgbpnycdv7tkj132g?guests=2&page='

page_number = 0
while true:
    page_number +=1
    try: 
        url = root + str(page_number)
        ### CODE #####
    except:
        ### terminare / print something ####

注意:我在您发布的链接中添加了“&page=”。尽管如此,它不会显示在第一页的url中。它仍然存在。如果添加“&page=1”,它将为玩具提供第一页。

我在 尽管如此:

    if not driver.find_elements_by_xpath("//*[contains(text(), 'Suivant')]"):
        break
    link=WebDriverWait(driver, 1530).until(expected_conditions.element_to_be_clickable((By.LINK_TEXT, "Suivant")))
    link.click()
    next_page = driver.find_element_by_css_selector('#pnnext')
    next_page.click()
    time.sleep(5)"""