如果我访问此页面 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/