【发布时间】:2016-02-08 11:38:09
【问题描述】:
我想在 Python 中加载 this page 中的图像列表。但是,当我在浏览器(Chrome 或 Safari)中打开页面并打开开发工具时,检查器返回的图像列表为 <img class="grid-item--image">...。
但是,当我尝试在 Python 中解析它时,结果似乎有所不同。具体来说,我得到的图像列表为<img class="carousel--image"...>,而soup.findAll("img", "grid-item--image") 确实返回了一个空列表。另外,我尝试使用其srcset 标签保存这些图像,大多数保存的图像不是网络上列出的。
我认为网页在渲染时使用了某种技术。如何成功解析网页?
我在 Python 3.5 上使用了 BeautifulSoup 4。我加载页面如下:
import requests
from bs4 import BeautifulSoup
html = requests.get(url).text
soup = BeautifulSoup(html, "html.parser", from_encoding="utf-8")
return soup
【问题讨论】:
标签: python parsing request beautifulsoup