在我的网站上运行Python脚本
问题描述:
我正在使用beautifulsoup
从网站上抓取数据。在我的网站上运行Python脚本
我的代码在我从PyCharm运行时工作。
当我在我的网站上运行它时(如newser.000webhost.com/new.py
)它不运行。
如何在我的网站上运行我的代码?
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)
答
000webhost是一个提供HTML,CSS,PHP和MySQL文件并且不是Python主机的Webhost。
如果您正在寻找一个完整的UNIX环境并托管您的Python文件,Digital Ocean是一个相当便宜(每月5美元)和可靠的VPS。
如果不熟悉或者想要*,我给你推荐PythonAnywhere或OpenShift
+0
你说得对。 000webhost无法运行该脚本。非常感谢你 :) –
如何你想运行脚本?您需要登录您的服务器或配置一些cgi以便从url运行python脚本... –
究竟发生了什么? “不运行 ”是什么意思?你做了什么可以让它运行吗? –