Advertisement
Sushill

main

Jul 8th, 2023
770
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. import aiohttp
  2. from bs4 import BeautifulSoup
  3. import asyncio
  4. from tool import userAgents
  5.  
  6. async def main():
  7.     url = "https://www.amazon.se/s?k=intel"
  8.     headers = {
  9.         "User-Agent": userAgents()
  10.     }
  11.  
  12.     async with aiohttp.ClientSession() as session:
  13.         async with session.get(url, headers=headers) as response:
  14.             html = await response.text()
  15.             # return html
  16.  
  17.     soup = BeautifulSoup(html, "html.parser")
  18.     # return soup.prettify()
  19.     products = soup.select_one("div[data-component-type='s-search-result']")
  20.     # return products
  21.     for product in products:
  22.         # title = product.find("a", _class="a-link-normal a-text-normal").text
  23.         title = product.select_one("a.a-link-normal.a-text-normal").text
  24.         # price = product.find("span", _class="a-price").text
  25.         price = product.select_one("span.a-price").text
  26.  
  27.         print(f"Title: {title}")
  28.         print(f"Price: {price}")
  29.  
  30.  
  31. if __name__ == '__main__':
  32.     print(asyncio.run(main()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement