刮擦蒸汽网

2024-04-19 18:57:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正试图网络刮蒸汽商店销售网页,但我可以刮所有的名称和折扣,但我不知道如何从数据中删除标签

我的代码是:

import bs4 as bs
import urllib.request

#opening a connection 
my_url = urllib.request.urlopen('https://store.steampowered.com/search/?specials=1&os=win').read()


#turning the html into a beautifulsoup object
soup = bs.BeautifulSoup(my_url, 'lxml')
def remove_tags(text):
    return ''.join(xml.etree.ElementTree.fromstring(text).itertext())

data_discounts = (soup.find_all('div', {'class':'col search_discount responsive_secondrow'}))
data_body = (soup.find_all('span', {'class':'title'}))
print (data_body)

Tags: textimporturlsearchdatabsrequestmy