Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/305.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
Python 我想刮无限滚动页面,有按钮加载更多的内容,这是我的代码_Python_Web Scraping - Fatal编程技术网

Python 我想刮无限滚动页面,有按钮加载更多的内容,这是我的代码

Python 我想刮无限滚动页面,有按钮加载更多的内容,这是我的代码,python,web-scraping,Python,Web Scraping,问题是,当我运行脚本时,我并没有获得page_源代码,selenium停止单击脚本中断,也并没有从page_源代码获取链接 从selenium导入webdriver 从bs4导入BeautifulSoup 从selenium.webdriver.support导入ui 导入时间 #url=“” driver=webdriver.Chrome(可执行文件\u path='C:/Users/yacerpc/Desktop/Chrome/chromedriver') 司机,上车https://www.

问题是,当我运行脚本时,我并没有获得page_源代码,selenium停止单击脚本中断,也并没有从page_源代码获取链接

从selenium导入webdriver
从bs4导入BeautifulSoup
从selenium.webdriver.support导入ui
导入时间
#url=“”
driver=webdriver.Chrome(可执行文件\u path='C:/Users/yacerpc/Desktop/Chrome/chromedriver')
司机,上车https://www.white-river-gems.com/shop')
while driver.find_element_by_class_name(“dn9KO”):
wait=ui.WebDriverWait(驱动程序,10)
button=wait.until(lambda驱动程序:driver.find元素通过类名称(“dn9KO”))
按钮。单击()
打印(“单击”)
html=driver.page\u源
soup=BeautifulSoup(html,'html.parser')
page=soup.find('div',{'class':''u1hm3\ujw2qu'})
查找链接=页面。查找所有('li'))
对于查找链接中的url:
link=url.find('a',{'class':''u2zthn'u2ahc6'}).get('href')
打印(链接)
我希望输出能够从page_source获得链接,请尝试如下操作:

driver.set_script_timeout(120)
driver.execute_async_script("""
  var interval = setInterval(() => {
    var button = document.querySelector('[data-hook="load-more-button"]')
    if(button){
      button.click()
    } else {
      clearInterval(interval)
      arguments[0]()
    }
  }, 5000)
""")
请注意,您希望选择
[data hook=“load more button”]
,因为
dn9KO
看起来会在下次部署时发生变化