我已经做了很多搜索,所以如果这是一个骗局我很抱歉.
无论如何,我需要获得当前文件的文件夹的名称.例如,我要转换的东西一样example.com/folder/subfolder/file.php
来subfolder
.
我当前的代码是dirname($_SERVER['PHP_SELF'])
,但返回/folder/subfolder
而不是subfolder
.谢谢!
我希望并排使用块元素.我不想使用left, right, top
,或任何类似的东西.
<div class="iLB">LOLOLOL</div>
<div class="iLB">
This is content.<br/>
This is content.<br/>
This is content.
</div>
<div class="iLB">This, too?</div>
Run Code Online (Sandbox Code Playgroud)
.iLB {
display: inline-block;
}
Run Code Online (Sandbox Code Playgroud)
现场演示:jsFiddle
我需要使用BeautifulSoup从页面获取所有文本.在BeautifulSoup的文档中,它表明你可以soup.get_text()
做到这一点.当我在reddit.com上尝试这样做时,我收到了这个错误:
UnicodeEncodeError in soup.py:16
'cp932' codec can't encode character u'\xa0' in position 2262: illegal multibyte sequence
Run Code Online (Sandbox Code Playgroud)
我在我检查的大多数网站上都遇到了类似的错误.
我也做了类似的错误soup.prettify()
,但是通过改变它来修复它soup.prettify('UTF-8')
.有没有什么办法解决这一问题?提前致谢!
6月24日更新
我发现了一些似乎适用于其他人的代码,但我仍然需要使用UTF-8而不是默认代码.码:
texts = soup.findAll(text=True)
def visible(element):
if element.parent.name in ['style', 'script', '[document]', 'head', 'title']:
return False
elif re.match('', str(element)): return False
elif re.match('\n', str(element)): return False
return True
visible_texts = filter(visible, texts)
print visible_texts
Run Code Online (Sandbox Code Playgroud)
但错误是不同的.进展?
UnicodeEncodeError in soup.py:29
'ascii' codec can't encode character u'\xbb' in position 1: ordinal not in range
(128)
Run Code Online (Sandbox Code Playgroud) 我需要一个Python相当于PHP的include函数.我知道execfile(),但这不起作用.有任何想法吗?
我有一个C#Visual Studio 2008表单,该表单需要读取相对文件'character / attacks.txt'的内容。即使我确定我的目录已经排序,运行它时File.Exists()也会返回false。码:
try
{
System.IO.StreamReader file = new System.IO.StreamReader("character/attacks.txt");
int counter = 0;
int numberOfLines = 0;
string line;
while ((line = file.ReadLine()) != null) { numberOfLines++; }
string[] attacks = new string[numberOfLines];
while ((line = file.ReadLine()) != null) { attacks[counter] = line; counter++; }
file.Close();
print(attacks.ToString());
}
catch (Exception ex)
{
print("ERROR"); print("Did you edit any files?"); print(ex.ToString());
}
Run Code Online (Sandbox Code Playgroud)
异常错误:
System.IO.FileNotFoundException: Could not find file 'D:\Users\Andrey\Desktop\Turn\character\attacks.txt'.
File name: 'D:\Users\Andrey\Desktop\Turn\character\attacks.txt'
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String …
Run Code Online (Sandbox Code Playgroud) 如果我不希望他们能够访问某个页面,我需要重定向用户.header('Location: ../acc/login.php');
例如,可靠性如何?浏览器可以忽略302错误,这是正确的方法吗?提前致谢!
我不知道该怎么做,我有一个39行的Python脚本,它在第40行给我一个错误!:(错误:
Traceback (most recent call last):
File "C:\Mass Storage\pythonscripts\Internet\execute.py", line 2, in <module>
execfile("firstrunSoup.py")
File "firstrunSoup.py", line 40
^
SyntaxError: invalid syntax
C:\Mass Storage\pythonscripts\Internet>
Run Code Online (Sandbox Code Playgroud)
这是我的Python代码:
###firstrunSoup.py###
FILE = open("startURL","r") #Grab from
stURL = FILE.read() #Read first line
FILE.close() #Close
file2save = "index.txt" #File to save URLs to
jscriptV = "not"
try:
#Returns true/false for absolute
def is_absolute(url):
return bool(urlparse.urlparse(url).scheme)
#Imports
import urllib2,sys,time,re,urlparse
from bs4 import BeautifulSoup
cpURL = urllib2.urlopen(stURL) #Human-readable to computer-usable
soup = BeautifulSoup(cpURL) #Defines soup
FILE = open(file2save,"a") …
Run Code Online (Sandbox Code Playgroud) 如果标题有点令人困惑,我很抱歉,但这是我的问题:
我需要使用PHP回显.html文件的来源.我尝试过使用PHP include(); 虽然文件的扩展名是.html.txt,但它显示为好像是.当我直接访问该文件时,例如"example.com/file.html.txt",它显示为正常的.txt.
这是我用来显示文件的PHP代码:
<div>
<?php
include "../head.php";
$path = $_GET["p"];
?>
<div style="position:absolute; top:90px; padding-left:5px; padding-right:10px;">
<?php
echo "<code>";
include("files/".$path);
echo "</code>";
?>
</div>
Run Code Online (Sandbox Code Playgroud)
我希望我能理解!:) 在此先感谢您的帮助!