To make the code send requests from different IP addresses, you can use proxy servers. You can set up a proxy server in the Playwright library with the following steps:

1. Install some proxy libraries if you haven’t already:

pip install proxybroker


2. You will need a list of proxy servers. You can obtain a list of proxy servers using the ‘proxybroker’ library. To find and collect a list of working proxies, use the following code snippet:

import asyncio
from proxybroker import Broker

async def show(proxies):
    while True:
        proxy = await proxies.get()
        if proxy is None:
            break
        print(‘Found proxy: %s’ % proxy)

proxies = asyncio.Queue()
broker = Broker(proxies)

# Collect 10 working HTTP(S) proxies
tasks = asyncio.gather(broker.find(types=[‘HTTP’, ‘HTTPS’], limit=10))

if asyncio.run_until_complete(tasks):
    print(‘Done.’)


This will provide you with a list of working proxies, store them in a list for using in your playwright code.

3. Update your main method to use the proxies while making requests with Playwright:

from random import choice

async def main():
    # Add the list of proxies collected with proxybroker
    proxy_list = [
        # Format: ‘http://username:password@proxy_ip:proxy_port’
        ‘http://username:password@proxy_ip:proxy_port’,
        ‘http://username:password@proxy_ip:proxy_port’,
        # Add more proxies as needed
    ]

    while True:
        # Randomly choose a proxy for each token_symbol
        for token_symbol in token_symbols:
            proxy = choice(proxy_list)
            result = await get_token_info(token_symbol, proxy)
            print(result)

        await asyncio.sleep(60)

# Modify your get_token_info function to accept a proxy parameter
async def get_token_info(token_symbol, proxy):
    # Existing code …
    async with async_playwright() as p:
        browser = await p.chromium.launch(headless=True, proxy={“server”: proxy})
        # Rest of the existing code …


These steps will ensure that the requests are sent using different IP addresses. Note that using free or public proxies can be unreliable and might affect the performance of your script. It’s recommended to use a reliable proxy service or your own proxy servers.

In conclusion, here’s the complete code with the integration of proxy:

import asyncio
from bs4 import BeautifulSoup
from random import choice
from playwright.async_api import async_playwright

async def get_token_info(token_symbol, proxy):
    async with async_playwright() as p:
        browser = await p.chromium.launch(headless=True, proxy={“server”: proxy})
        # Rest of the existing code…

# Add the list of proxies collected with proxybroker
proxy_list = [
    # Format: ‘http://username:password@proxy_ip:proxy_port’
    ‘http://username:password@proxy_ip:proxy_port’,
    ‘http://username:password@proxy_ip:proxy_port’,
    # Add more proxies as needed
]

async def main():
    while True:
        # Randomly choose a proxy for each token_symbol
        for token_symbol in token_symbols:
            proxy = choice(proxy_list)
            result = await get_token_info(token_symbol, proxy)
            print(result)

        await asyncio.sleep(60)

token_symbols = [
    “0x0E481Fa712201f61dAf97017138Efaa69e2A3df3”,
    “0x2023aa62A7570fFd59F13fdE2Cac0527D45abF91”,
    “0x2222222222222222222222222222222222222222”,
    “0x0d4890ecEc59cd55D640d36f7acc6F7F512Fdb6e”]

asyncio.run(main())

The above code allows you to send requests from different ip addresses. will this be enough to parse the site, will they block ip addresses?

If that's not enough, please suggest a better way.