私はhtml tdタグから単価値を取得しようとしていますが、同じクラス名の他のtdがあります。下記の画像を参照してください。ここenter image description herePythonのtdからのみ価格を選択
は私がループのために価格をスライスした場合、それが唯一の最初の価格を取得しますが、私は一度にすべての価格を持ちたい
from builtins import any as b_any
from urllib.parse import urlparse
from urllib.parse import urljoin
from collections import Counter
import urllib.request
import csv
import schedule
import time
import re
from bs4 import BeautifulSoup
url="http://offer.ebay.es/ws/eBayISAPI.dll?ViewBidsLogin&item=122713288532&rt=nc&_trksid=p2047675.l2564"
req = urllib.request.Request(url, headers={'User-agent': 'Mozilla/5.0'})
htmlpage = urllib.request.urlopen(req)
html = htmlpage.read().decode('utf-8')
soup = BeautifulSoup(html,"html.parser")
table = soup.find_all('td',{'class':'onheadNav'})
'''for txt in table:
nametxt = txt.text
result = ''.join([i for i in nametxt if not i.isdigit()])
cleantxt = result.replace('(','')
print(cleantxt.replace(')',''))
rank = txt.a.text
print(rank)'''
price = soup.select('td.contentValueFont')
for pr in price:
print(pr.text)
を書かれているコードがあります。
編集説明: 私はすべての価格をキャプチャしたいが、同じクラス名のtdが3つあり、Cantidad(数量)の価格1と、これらのすべてが同じクラスです。私が価格セクションだけを取得しようとすると、私のコードは3つのtdを返します。私はあなたが今、それを得る
あなたの説明では矛盾しています:**単価の値を取得する** <-> **すべての値をすぐに持ちたい**。あなたの質問を更新してください – RomanPerekhrest
私はすべての価格をキャプチャしたいのですが、問題は同じクラス名を持つ3つのtdがあります.dはCantidad(数量)の価格の1つで、日付のものはすべて同じクラスです。私が価格セクションだけを取得しようとすると、私のコードは3つのtdを返します。あなたは今それを得ることを願っています。 –
私はbeautifulsoupをよく知っていませんが、クラスごとに取得するのではなく、td(例えば 'td [1]')を取得しようとするかもしれません。 – Stephan