イメージからタイトルを抽出しようとしています。私はurl
を抽出することができましたが、イメージのタイトルの抽出をどのようにコードするかはわかりません。 The HTML is:Python BeautifulSoup Titile Web Crawlerを抽出する
<a itemprop="url" class="ad-listing__thumb-link" name="1124692138" href="/s-ad/derrimut/cars-vans-utes/2015-toyota-86-coupe-12-month-warranty-/1124692138" data-ref="searchTopAd">
<span id="r-image-TOP_AD-1124692138" title="2015 Toyota 86 Coupe **12 MONTH WARRANTY** Derrimut Brimbank Area Preview" class="j-responsive-image ad-listing__thumb" data-index="1">...</span>
</a>
最初の行がhref
ですが、私は、HTMLのspan
ブロックごとなどtitle
が強調表示を取得したい
import requests
from bs4 import BeautifulSoup
def trade_spider(max_pages):
page = 1
while page <= max_pages:
url = 'http://www.gurstree.com.au/s—cars—vans—utes/melbourne/page—' + str(page) + '/c1832013001317'
source_code = requests.get(url)
plain_text = source_code.text
soup = BeautifulSoup(plain_text)
for link in soup.findAll('a', {'class': 'ad—listing_title—link'}):
href = 'http://www.gumtree.com.au/' + link.get('href')
print(href)
page += 1
trade_spider(1)
。
ありがとうございます!
import re
soup.find('span', id=re.compile(r'r-image'))
あなたのコードではなく、画像 –
を投稿uはここにURLを追加することができます。次の
span
を見つけ、addribute内の文字列に一致するようにtitle
使用regexを取得する
使用
–.
が