python-3.x - 为什么抓取检测只有 20 个 img 标签?
问题描述
from urllib.request import Request,urlopen,urlretrieve
import urllib
from bs4 import BeautifulSoup
key = input("Enter the image to be searched \n")
urlpath = "https://www.google.com/search?
q="+key+"&source=lnms&tbm=isch&sa=X&ved=0ahUKEwiE9-
7LjobfAhXCEHIKHQy6A00Q_AUIDigB&biw=1920&bih=947#imgrc=_"
page_req = Request(urlpath, headers={'User-Agent': 'Mozilla/5.0'})
page= urlopen(page_req).read()
soup =BeautifulSoup(page,'html.parser')
images= soup.find_all('img')
print("Total"+str(len(images)))
image_links=[]
for img in images:
image_links.append(img.get('src'))
image_count=0
for link in image_links:
urlretrieve(link,'image_'+str(image_count)+'.jpg')
image_count+=1
上面的脚本只从谷歌图片页面检测到 20 个图片标签。为什么它无法检测到网页中的所有图像标签?
解决方案
该 URL 处的 HTML 文档仅包含 20 张图像。
其余部分在页面加载后通过使用 JavaScript 修改 DOM 来加载。
推荐阅读
- python - Serializers.validated_data 字段随 DRF 中的源值而更改
- c++ - IIS 在回收期间是否取消/注册 C++ COM 库?
- linux - 如何使用 Gmail 为 Airflow 电子邮件警报设置 SMTP 服务器
- swiftui - iOS 15 上的 SwiftUI,自定义按钮样式不再起作用,它在 iOS 14 上运行良好,如何解决?
- java - 如何返回一个 Mono 空对象,以便它被 application/json 格式接受?
- python - Pandas 与每日间隔的值的最大差异
- reactjs - 自定义挂钩的返回值不会在其文件之外更新
- pytorch - 为什么我的带有 CTCloss 的 RCNN 模型不起作用?
- powerbi - 比较 DAX 中的两个过滤表
- jenkins - Jenkinsfile 如何遍历子文件夹/子文件名?