Irtiza Hammad Irtiza Hammad - 12 days ago 6
HTTP Question

Run a Python script on my website

I am using

beautifulsoup
to scrape data from websites.

My code works when I run it from PyCharm.

When I run it on my website (like
newser.000webhost.com/new.py
) it does not run.

How can I run my code on my site?

import requests
from bs4 import BeautifulSoup

def trade_spider(max_pages):

page = 1

while page <= max_pages:
url = 'https://www.geo.tv/category/sports/'+ str(page)
source_code = requests.get(url, allow_redirects=False)
plain_text = source_code.text.encode('ascii', 'replace')
soup = BeautifulSoup(plain_text, 'html.parser')

for div in soup.findAll('div', {'class': 'geo-zoom-effect'}):
for a in div.findAll('a'):
title = a.get('title')
href = a.get('href')
print title
print href

for img in a.findAll('img'):
src=img.get('src')
print src

page+=1

trade_spider(5)

Answer

000webhost is a Webhost that serves HTML,CSS, PHP and MySQL files and is not a Python host.

Digital Ocean is a fairly cheap ($5/month) and reliable VPS if you're looking for a full UNIX environment and host your Python files.

If not familiar or want free I'll recommend PythonAnywhere or OpenShift