更新:感谢大家深夜的帮助。我已经用我所做的修改更新了下面的代码。如果一句话被注释了,那是我尝试过的,但它没有成功,现在没有注释掉的是我最后一次尝试。我仍然不能让我的网页加载。再次谢谢你!!
网站位置:www.encapdio.com/pyscper.php,我是一个系统专家,尝试编程,并决定把网站放在一起学习php。我的代码,如果导致页面出错500,即使我的php.ini文件显示错误,它似乎也只是中断。我在代码中找不到任何错误,但我很可能需要一双全新的眼睛。这就是它应该做的。
本页的目的是抓取每一行股票代码。一旦您点击submit,我的代码应该检查文本区域是否为空。如果它不是空的,然后将$content接收到数组中,将$linebreak添加到每个数组项的末尾,并说明\r类型的换行,然后逐行将每个条目写入文件中。如果没有输入任何代码,则回显空。
然后,如果一切都成功了,并且状态=结果,你就可以看到股票价格旁边的代码。我有一个经过充分测试的python脚本,它检查将执行我的webcrawler/scraper/ticker_inputs.txt更新程序的ticker_inputs.txt文件。
在没有服务器错误500的情况下,我无法更新ticker_input.txt文件,甚至无法在同一页面上显示php和html。
示例代码:
<?php
include("inc/header.php");
include("inc/nav.php");
#if (isset ($_POST[$text_name])) && $_POST['text_name'] != "") {
if (!empty($_POST['textfile'])) {
$content = isset($_POST['textfile'])?$_POST['textfile']:"";
$linebreak = explode("\n", str_replace("\r", "", $content));
$tick_wfile = fopen("ticker_input.txt", "w") or die("Unable to open file!");
fwrite($tick_wfile,$linebreak);
fclose($tick_wfile);
if (empty($_POST['textfile'])) {
echo "No Tickers Were Entered!";
}
header("Location: pyscraper.php?status=results");
exit;
}
include("inc/header.php");
include("inc/nav.php"); ?>
<div class="container" align="center">
<div class="page-header">
<br><h1>Web Scraper<small> built with python</small></h1>
<?php if (isset($_GET["status"]) && $_GET["status"] == "results") {
$tick_rfile = fopen("ticker_input.txt","r") or die("Unable to open file after writting to it!");
echo fread($tick_rfile,filesize("ticker_input.txt"));
fclose($tick_rfile);
} else { ?>
<form name="savefile" method="post" action="">
<fieldset class="form-group">
<label for="tickerlist">Enter Tickers <small>(one per line)</small></label>
<textarea name="textfile" class="form-control" rows="5"></textarea>
</fieldset>
<button type="submit" name="submit_file" value="Save File" class="btn btn-primary">Submit</button>
</form>
<?php } ?>
</div>
</div>
<?php include("inc/footer.php"); ?>发布于 2016-02-10 05:53:20
试着改变:
header("location:pyscraper.php?status=results");至
header("Location: pyscraper.php?status=results");
exit;基本上,如果没有exit;,其余的PHP仍然会被执行。还有HTTP headers are case sensitive。
如果这不起作用,我将删除答案。将其作为评论发布可能会更难理解。
发布于 2016-02-10 05:59:04
这一行中缺少一个结束括号。
$linebreak = explode("\n", str_replace("\r", "", $content);
检查您的代码
发布于 2016-02-10 06:03:09
在isset之后的第四行中缺少了一个公开的偏执。
此外,您也不能使用空()对函数call.Try使用isset进行检查。$_POST‘’textfile‘总是被设置,但可以是空的。
查看this link以获得更多信息
https://stackoverflow.com/questions/35307779
复制相似问题