python网页抓取,提取标签的内部元素

标签 python web-scraping

我想从在线购物网站抓取产品和价格,需要帮助提取标签之间写入的字符串

import bs4
from urllib.request import urlopen
from bs4 import BeautifulSoup as soup
my_url='https://www.flipkart.com/cameras/mirrorless~type/pr?sid=jek%2Cp31'
cl=urlopen(my_url)
page_html=cl.read()
ps=soup(page_html,'html5lib')
ps1=(ps.prettify())
cn=ps.findAll('div',{'class':'_1-2Iqu row'})
len(cn)                     
cn[0].div.div

#output-"<div class="_3wU53n">Canon M50 Mirrorless Camera Body with Single Lens EF-M 15-45 mm ISSTM</div>
#i need Canon M50 Mirrorless Camera Body with Single Lens EF-M 15-45 mm ISSTM

最佳答案

将 cn=ps.findAll('div',{'class':'_1-2Iqu row'}) 替换为 cn=ps.findAll('div',{'class':'_1-2Iqu row'} ,文本=真)

关于python网页抓取,提取标签的内部元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59583717/

相关文章:

python - 让 PyC​​harm 识别 Anaconda 的 SciPy

python - 通过网络抓取使用帖子从网站获取结果

python-3.x - Selenium WebDriverWait 在网络抓取时在 Python 上返回错误

python - Pandas :估算 NaN 的

python - 如何在 Windows 10 中安装 atari-py?

python - 导入 opencv 模块

python - Tensorboard 无法导入名称 `run_main`

node.js - 如何管理 'pool' 的 PhantomJS 实例

python - 使用 BeautifulSoup 和 Mechanize 登录网页

web-scraping - Scrapy,如何更改输入表单中的值,提交然后抓取页面