我正在使用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)
如何你想運行腳本?您需要登錄您的服務器或配置一些cgi以便從url運行python腳本... –
究竟發生了什麼? 「不運行 」是什麼意思?你做了什麼可以讓它運行嗎? –