python - BeautifulSoup 不在 html 页面中显示某些标签

标签 python python-3.x web-scraping beautifulsoup

如果我访问此页面 here ,我可以在检查时看到带有 img 标签的页面上的图像。

但是当我尝试使用 requests 获取页面并使用 BeautifulSoup 进行解析时,我无法访问相同的图像。我在这里缺少什么?

代码工作正常,我从请求中得到 200 作为 status_code。

import requests
from bs4 import BeautifulSoup

url = 'https://mangadex.org/chapter/435396/2'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36'}

page = requests.get(url,headers=headers)
print(page.status_code)

soup = BeautifulSoup(page.text,'html.parser')
img_tags = soup.find_all('img')
for img in img_tags:
    print(img)

编辑::

根据建议,selenium 选项工作正常。但是有没有办法像 BeautifulSoup 那样加快速度呢?

最佳答案

页面包含需要运行的 JavaScript 以填充页面上的某些元素。你可以使用 Selenium在访问图像之前运行页面的 JavaScript。

关于python - BeautifulSoup 不在 html 页面中显示某些标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55426871/

相关文章:

python - 如何在自定义 handler500 中获取异常?

java - 如何抓取 HTTPS javascript 网页

尝试在不同路径中导入模块时出现 Python ImportError

python - 如何安装 Python Pandas ?

python - 在 Python 中,为什么用 C 实现的模块比纯 Python 模块更快,我该如何编写一个模块?

python-3.x - plot_decision_regions 错误 "Filler values must be provided when X has more than 2 training features."

python - 查看函数是否被调用

python - BeautifulSoup 与 find all 只给出最后的结果

node.js - 如何在node.js中将图像从请求传输到pdfkit?

python -++增量运算符的等价物是什么?