【发布时间】:2019-05-11 18:11:17
【问题描述】:
我想解析页面中的一些信息,但是遇到了一些麻烦,因为我无法解析没有 id 或 class 的东西。 现在我有标签 div,里面有图像和一些文本(数字)我需要得到这个数字,但是这个 div 只有样式标签,我不能使用这个样式标签,因为他总是在改变。
我有类似游戏网站拍卖的东西,并试图解析物品名称、价格和链接。 但现在我只能得到名字。
我正在尝试为具有父类的 div 查找所有“a”。 我试图找到href 我正在尝试按样式查找
def rshp_parse (base_url, headers):
session = requests.Session()
request = session.get(base_url, headers=headers)
if request.status_code == 200:
soup = bs(request.content, 'html.parser')
divs = soup.find_all('div', class_={'shop-search-row'})
for div in divs:
title = div.find('span').text
price = div.find('div')
href = div.find('a', class_={'champions_container'})['href']
# href = soup.find('div', style='color:#FFFFFF;text-decoration:none')
HTML
<div style="display:inline-block;width:15%;line-height:50px;vertical-align:top;white-space: nowrap;">
<img src="/assets/rpc/shard.png" style="width:20px">35,000
</div>
35,000 - 这是我所需要的
<a href="/market/auction/1227124" target="_blank" style="color:#FFFFFF;text-decoration:none">
还有这个链接
【问题讨论】:
-
可以分享一下网址吗?
标签: python parsing web-scraping beautifulsoup python-requests