2016-11-26 109 views
-2

我正在使用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) 
+0

如何你想運行腳本?您需要登錄您的服務器或配置一些cgi以便從url運行python腳本... –

+0

究竟發生了什麼? 「不運行 」是什麼意思?你做了什麼可以讓它運行嗎? –

回答

1

000webhost是一個提供HTML,CSS,PHP和MySQL文件並且不是Python主機的Webhost。

如果您正在尋找一個完整的UNIX環境並託管您的Python文件,Digital Ocean是一個相當便宜(每月5美元)和可靠的VPS。

如果不熟悉或者想要自由,我給你推薦PythonAnywhereOpenShift

+0

你說得對。 000webhost無法運行該腳本。非常感謝你 :) –

相關問題