【问题标题】:Google App Engine urlFetch truncates page textGoogle App Engine urlFetch 截断页面文本
【发布时间】:2012-08-14 20:43:05
【问题描述】:

我正在使用 GAE python 2.5 和 Beautiful Soup 3.08,并且正在发生一些事情,切断了我的文本的第一部分。

这是我的代码:

from google.appengine.api import urlfetch
from BeautifulSoup import BeautifulSoup

url = 'http://www.cmegroup.com/CmeWS/mvc/xsltTransformer.do?xlstDoc=/XSLT/da/DailySettlement_CPC-FUT.xsl&url=/da/DailySettlement/V1/DSReport/ProductCode/J4/FOI/FUT/EXCHANGE/XNYM/Underlying/J4?tradeDate=08/16/2012'

print '<hr>This is the raw result fetched (print result.content)<hr>'
result = urlfetch.fetch(url = url, method = urlfetch.GET)
print result.content

soup = BeautifulSoup(result.content)
print '<hr>This is prettified soup (soup.prettify)<hr>'
print soup.prettify()

print '<hr>here is the print out of iteration through the findall<hr>Go!<br>'
trSet = soup.findAll('tr')
if trSet is not None:
  for i in trSet:
    i.string
else:
  print "Couldn't find TRs in Soup!"

我运行此代码的应用网站是:http://mwp-test2.appspot.com/ 正在发生的是第一次打印根本没有发生。有任何想法吗? (我也遇到了 Beautiful Soup 的 findAll 问题,但我打算在弄清楚这个截断问题后提出这个问题)

【问题讨论】:

    标签: python google-app-engine beautifulsoup


    【解决方案1】:

    当我运行您的页面时,第一次打印似乎确实有效。此外,您应该使用 response.out.write 而不是 print。看看这里的文档:https://developers.google.com/appengine/docs/python/tools/webapp/overview

    【讨论】:

    • 我之前已经通读了整个“入门”部分,但已经开始剥离部分进行调试。看起来我太精简了,使用链接中设置的 WSGI 就可以了!谢谢先生
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-03
    • 2010-12-30
    • 2012-11-24
    • 1970-01-01
    • 2011-01-10
    相关资源
    最近更新 更多