Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import aiohttp
- from tool import userAgents
- import logging
- import asyncio
- from bs4 import BeautifulSoup
- async def main():
- url = "https://www.amazon.se/s?k=intel"
- headers = {
- "User-Agent": userAgents()
- }
- async with aiohttp.ClientSession() as session:
- try:
- async with session.get(url, proxies=proxy, headers=headers) as response:
- html = await response.text()
- if amazon.useProxy and not response.connection.proxy_manager:
- logging.error(
- build_log_message(
- colored("request gjordes utan proxy. Stänger ner....", "red")
- )
- )
- return None
- soup = BeautifulSoup(html, "html.parser")
- products = soup.select_one("div[data-component-type='s-search-result']")
- for product in products:
- title = product.select_one("a.a-link-normal.a-text-normal").text
- price = product.select_one("span.a-price").text
- print(f"Title: {title}")
- print(f"Price: {price}")
- except aiohttp.ClientError as e:
- logging.error(build_log_message("Inget svar vid requests..."))
- return None
- # Call the `main` function to run the code asynchronously
- asyncio.run(main())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement