美しいスープを使用してウェブサイトから一部のデータを取得していますが、印刷中にデータからhtmlタグを削除できません。参照されるコードは次のとおりです。
import csv
import urllib2
import sys
from bs4 import BeautifulSoup
page = urllib2.urlopen('http://www.att.com/shop/wireless/devices/smartphones.html').read()
soup = BeautifulSoup(page)
soup.prettify()
for anchor1 in soup.findAll('div', {"class": "listGrid-price"}):
print anchor1
for anchor2 in soup.findAll('div', {"class": "gridPrice"}):
print anchor2
for anchor3 in soup.findAll('div', {"class": "gridMultiDevicePrice"}):
print anchor3
これを使用して取得している出力は、次のようになります。
<div class="listGrid-price">
$99.99
</div>
<div class="listGrid-price">
$0.01
</div>
<div class="listGrid-price">
$0.01
</div>
周りにhtmlタグを付けずに、出力の価格のみが必要です。私はプログラミングに不慣れなので、私の無知を許してください。