【发布时间】:2022-01-23 23:29:44
【问题描述】:
我正在尝试废弃 Magic Eden,特别是我想要获取页面中存在的所有集合的页面集合。我想我已经完成了一半,但我无法弄清楚下面的两个问题。
import requests
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
url = "https://magiceden.io/collections"
chrome_options = Options()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome("../chromedriver/chromedriver")
# driver = webdriver.Chrome("../chromedriver/chromedriver",chrome_options=chrome_op tions)
driver.get(url)
## There is a catch with the site, it loads more data when you scroll down so I need to add this function part to scroll until the end
while driver.find_element_by_tag_name('div'):
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
Divs=driver.find_element_by_tag_name('div').text
if 'End of Results' in Divs:
print('end')
break
else:
continue
"""
Q1 : I need to find a way to break out the while loop. I don't seem to find a pattern in the end of the page
"""
"""
Q2 : How do I get after loading the page, all of the href and the names of each project ?
"""
【问题讨论】:
-
网页无限滚动,你想在什么情况下突破?
-
项目数量有限。如果你运行我的代码行并检查页面,你会看到你走到了页面的末尾,但是循环仍在继续,因为我不知道如何找到一个好的模式来打破它。跨度>
标签: python selenium web-scraping