简体   繁体   English

Jsoup1.7.2无法使用Google App Engine 1.7.5

[英]Jsoup1.7.2 isn't working google app engine 1.7.5

I'm working on a project where my application is hosted on Google App Engine and uses Jsoup html parsing library. 我正在一个项目中,我的应用程序托管在Google App Engine上,并使用Jsoup html解析库。 In my application I'm using TaskQueues with the default queueu, the only task in that queue is to connect to a URL and start parsing the page. 在我的应用程序中,我将TaskQueues与默认的queueu一起使用,该队列中的唯一任务是连接到URL并开始解析页面。 No errors or warnings appear in the log files, it just exits as it doesn't see the line of Jsoup parsing the document. 日志文件中没有错误或警告,只是退出了,因为看不到Jsoup解析文档的行。 Here is a snippet of my code: 这里是我的代码片段:

log.warning("Before connection");
Document doc = Jsoup.connect("http://en.wikipedia.org/").get();
log.warning("After connection");

The TaskQueue works fine, I've tested and I'm 100% sure that there is no problem with it. TaskQueue工作正常,我已经测试过,而且我100%确信它没有问题。 I've tried to manually connect to the webpage and download it then pass it to Jsoup and start parsing it there, the connection worked fine and the webpage was downloaded successfully, but yet Jsoup wasn't able to do anything. 我尝试手动连接到该网页并下载它,然后将其传递给Jsoup并开始在那里解析,该连接工作正常,该网页已成功下载,但是Jsoup无法执行任何操作。 My biggest problem is that there no errors and no warnings in the log file; 我最大的问题是日志文件中没有错误,也没有警告。 so I don't know what it is going on. 所以我不知道这是怎么回事。

App engine restricts a number of of classes, I would assume that either the Jsoup.connect(url) or the .parse method depends on one of those restricted classes and throws an exception. App Engine限制了许多类,我假设Jsoup.connect(url)或.parse方法依赖于那些受限制的类之一并引发异常。

To eliminate the chance of the Jsoup.connect causing issues then I'd suggest you use App Engine URL Fetch to get a String of the page at the URL and then use: 为了消除Jsoup.connect引起问题的机会,建议您使用App Engine URL FetchURL上获取页面的字符串,然后使用:

Document doc = Jsoup.parse(htmlString);

However if there are issues with the parse then you really need to get errors/logging working and there's not a lot of info here yet to be able to suggest something. 但是,如果解析存在问题,那么您真的需要使错误/记录正常工作,并且这里没有太多信息可以提出建议。 Try to put the problematic code in a try-catch block and see if you can catch an exception. 尝试将有问题的代码放入try-catch块中,看看是否可以捕获异常。

Additionally try a later version of GAE SDK (1.8.1 is the current one). 此外,请尝试使用更高版本的GAE SDK(当前版本为1.8.1)。 I've previously had a conflict with GAE SDK's checkRestricted method that interfered with Jsoup, so that may be the case with 1.7.5. 我以前与GAE SDK的checkRestricted方法发生冲突,该方法干扰了Jsoup,因此1.7.5可能就是这种情况。

The problem was that I was using Jsoup 1.7.2 which is clearly not very compatible with Google App Engine. 问题是我使用的Jsoup 1.7.2与Google App Engine显然不兼容。 I switched back to Jsoup 1.7.1 and the problem was fixed. 我切换回Jsoup 1.7.1,此问题已解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM