Web scraping 我没有得到这个python代码的任何输出

Web scraping 我没有得到这个python代码的任何输出,web-scraping,beautifulsoup,web-crawler,Web Scraping,Beautifulsoup,Web Crawler,我建议使用SeleniumWebDriver获取所有页面源代码,然后对其进行解析 from bs4 import BeautifulSoup import requests import os url = requests.get("https://www.pexels.com/search/flower/") soup = BeautifulSoup(url.text, "html.parser") links = [] x = soup.select('img[src^="https:

我建议使用SeleniumWebDriver获取所有页面源代码,然后对其进行解析

from bs4 import BeautifulSoup
import requests
import os

url = requests.get("https://www.pexels.com/search/flower/")
soup = BeautifulSoup(url.text, "html.parser")

links = []

x = soup.select('img[src^="https://images.pexels.com/photos"]')

for img in x:
    links.append(img['src'])

for l in links:
    print(l)
geckodriver的最新版本,它是运行此代码所必需的

我确实得到了以下输出:

from bs4 import BeautifulSoup
from selenium import webdriver

url = "https://www.pexels.com/search/flower/"

options = webdriver.FirefoxOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument('--ignore-ssl-errors')
options.headless = True
driver = webdriver.Firefox(executable_path="./geckodriver", options=options)

driver.get(url)
content = driver.page_source
driver.quit()

soup = BeautifulSoup(content, "html.parser")
links = []
x = soup.select('img[src^="https://images.pexels.com/photos"]')
for img in x:
    links.append(img['src'])
for l in links:
    print(l)

你想做什么?这个网站是受CloudFlare保护的。我实际上是想在网站上搜刮图片。你能解释一下为什么在获取页面源代码后关闭浏览器吗?不客气!但如果我的答案对你有帮助,你可以投票支持它:)
https://images.pexels.com/photos/36753/flower-purple-lical-blosso.jpg?auto=compress&cs=tinysrgb&dpr=1&w=500
https://images.pexels.com/photos/3860667/pexels-photo-3860667.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500
https://images.pexels.com/photos/133472/pexels-photo-133472.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500
https://images.pexels.com/photos/4618416/pexels-photo-4618416.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500
https://images.pexels.com/photos/4234543/pexels-photo-4234543.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500
...
https://images.pexels.com/photos/4492525/pexels-photo-4492525.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500
https://images.pexels.com/photos/4210784/pexels-photo-4210784.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500
https://images.pexels.com/photos/4210781/pexels-photo-4210781.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500