我正试图从1mg网站上刮取网页的HTML
在URL中,当我尝试将其保存为HTML时,或者当我尝试使用BeautifulSoup将其刮取时,返回None
用于刮削的代码:
from bs4 import BeautifulSoup
import requests
headers = {"User-Agent":'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36'}
url='https://www.1mg.com/categories/ayurveda/top-brands-265?filter=true&brand=Dabur'
page= requests.get(url, headers=headers)
soup=BeautifulSoup(page.content,'html.parser')
img=soup.find_all('img',{'class':'style__image___Ny-Sa style__loaded___22epL'})
for i in img:
i['src']
这是要刮取的图像的示例标记:
<img alt="Dabur Shilajit Gold Capsule" src="https://res.cloudinary.com/du8msdgbj/images/w_150,h_150,c_fit,q_auto,f_auto/v1603435745/feaoalhp4c6bv8icllgp/dabur-shilajit-gold-capsule.jpg" title="Dabur Shilajit Gold Capsule" class="style__image___Ny-Sa style__loaded___22epL">
我已经手动复制了上面的标记作为示例。我对产品名称和价格使用了相同的代码(更改了标签),效果很好。我甚至尝试使用img标签的父标签
页面是动态加载的,因此} 模块获取所有图像(总共40个)
requests
不支持它。但是,该数据在网站上以JSON格式提供,请尝试使用内置的^{输出:
相关问题 更多 >
编程相关推荐