Skip to content

Commit

Permalink
[#7] Implement ads_top_url
Browse files Browse the repository at this point in the history
  • Loading branch information
malparty committed Jun 15, 2021
1 parent bc141b7 commit 333e515
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/services/google_service/parser_service.rb
Expand Up @@ -28,7 +28,8 @@ def ads_page_count
end

def ads_top_url

# data-ved enables to filter "role=list" (sub links) items
@document.css('#tads div[data-text-ad] a[data-ved]').map { |a_tag| a_tag['href'] }
end

def ads_page_url
Expand Down
9 changes: 9 additions & 0 deletions spec/services/google_service/parser_service_spec.rb
Expand Up @@ -33,5 +33,14 @@
expect(described_class.new(result).ads_page_count).to eq(6)
end

it 'find 3 different top ads url' do
result = nil
VCR.use_cassette('google_search_top_ads_6') do
result = GoogleService::ClientService.query('vpn')
end

expect(described_class.new(result).ads_top_url).to contain_exactly('https://cloud.google.com/free','https://www.expressvpn.com/', 'https://www.top10vpn.com/best-vpn-for-vietnam/')
end

end
end

0 comments on commit 333e515

Please sign in to comment.