reProx / app.py
OzoneAsai's picture
Update app.py
21e7cd4
Raw
History Blame Contribute Delete
1.93 kB
import streamlit as st
import requests
from bs4 import BeautifulSoup
import re
def main():
st.title("Enhanced Proxy Server")
# Get URL input from the user
url = st.text_input("Enter URL to proxy:", "https://www.example.com")
# Display the URL
st.write("Proxying requests to:", url)
# Add any additional options or features as needed
# Create a simple form to submit requests
user_input = st.text_input("Enter request parameters (if any):", "")
if st.button("Send Request"):
# Make a request to the specified URL
response = make_request(url, user_input)
# Extract and proxy links and JavaScript requests
proxied_html = proxy_links_and_js(url, response.text)
# Display the original HTML in one column and the proxied HTML in another column
st.subheader("Original HTML:")
st.markdown(response.text)
st.subheader("Proxied HTML:")
st.markdown(proxied_html)
def make_request(url, params):
# Make an HTTP GET request to the specified URL with optional parameters
response = requests.get(url, params=params)
return response
def proxy_links_and_js(base_url, html_content):
# Use BeautifulSoup to parse the HTML
soup = BeautifulSoup(html_content, "html.parser")
# Find all links (a tags) in the HTML
links = soup.find_all("a", href=True)
for link in links:
# Modify each link to be a proxied link
link["href"] = f"/proxy?target={base_url}/{link['href']}"
# Find all script tags with a src attribute (JavaScript)
script_tags = soup.find_all("script", src=True)
for script_tag in script_tags:
# Modify each script source to be a proxied link
script_tag["src"] = f"/proxy?target={base_url}/{script_tag['src']}"
# Return the modified HTML with proxied links and JavaScript sources
return str(soup)
if __name__ == "__main__":
main()