この問題を解決する方法を見つけようとしているうちに、私は行き詰まってしまった。
私はBS4のfindAll()関数を使用してタグ付き製品ページを解析しています。正しい応答が得られますが、私が探している領域はBS4を使ってフィルタリングできるタグなしの "プレーンテキスト"私は理解している
def find_product(counter):
url = base_url
print('Looking in ' + url)
while not matches[counter]:
print(datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S'))
try:
response1 = search_session.get(url)
except:
print('Unable to connect to site...')
if counter == checkout_qty - 1:
sys.exit()
else:
continue
soup1 = bs(response1.text, 'html.parser')
#soup1.find_all('script')
soup2 = soup1.findAll('script', text = re.compile('id : ')) #using text recompiling doesn't really do anything,just gives a slightly cleaner output of findings.
print(soup2)
for ids in soup2:
link = ids.find(text = re.compile('id'))
#i think i should use it somehow here,but I lack knowledge
#this loop is unfinished
break
これは私が製品ページから解析しているものです。
<main class="B__container">
<script>
product.p = {
id : 47755536459,
title : "PRODUCT NAME",
handle : "PRODUCT HANDLE",
vendor : "",
available : ,
images : ["image-link.com\/files\/1111"],
featured_image : "image-link.com\/files\/1111",
options : ["Size"],
tags : [],
price : 24000,
variants : []
};
product.p.variants.push({
id : 40113207495,
parent_id : 10025946759,
available : false,
featured_image : null,
public_title : null,
requires_shipping : true,
price : 24000,
options : ["4"],
option1 : "4",
option2 : "",
option3 : "",
option4 : ""
});
product.p.variants.push({
id : 40113207559,
parent_id : 10025946759,
available : false,
featured_image : null,
public_title : null,
requires_shipping : true,
price : 24000,
options : ["4.5"],
option1 : "4.5",
option2 : "",
option3 : "",
option4 : ""
});
product.p.variants.push({
id : 40113207623,
parent_id : 10025946759,
available : false,
featured_image : null,
public_title : null,
requires_shipping : true,
price : 24000,
options : ["5"],
option1 : "5",
option2 : "",
option3 : "",
option4 : ""
});
</script>
私の目標は、数字でIDを抽出し、後でそれを別の機能に送信することです。
問題がある、知識が不足している、または私が望むものを得るためにBS4をどのように使用するかのスキルが欠けています。
あなたはURLを投稿できますか?あなたは2つの可能な解決方法があります:1)ウェブサイトから直接情報を入手しようとするか、2)このテキストブロックを処理して、あなたが望むものを得る... –
「変種」のこれらの配列は、タスクのために。私は 'id'を集める必要があります。具体的には、数字 'id'が割り当てられていて、それをカートに追加するために使用します。必要なデータをフィルタリングするために、これらの配列/ブロックをコールドプロセスでどのように処理するかに関するガイドラインを教えてください。 – zekron
"これは私が製品ページから解析しているもの"の後に続くテキストブロックです。 'soup2'ですか? –