我想从我的服务器日志中获取" GET "查询.
例如,这是服务器日志
1.0.0.127.in-addr.arpa - - [10/Jun/2012 15:32:27] code 404, message File not fo$
1.0.0.127.in-addr.arpa - - [10/Jun/2012 15:32:27] "GET /hello HTTP/1.1" 404 -
1.0.0.127.in-addr.arpa - - [10/Jun/2012 15:41:57] code 404, message File not fo$
1.0.0.127.in-addr.arpa - - [10/Jun/2012 15:41:57] "GET /ss HTTP/1.1" 404 -
Run Code Online (Sandbox Code Playgroud)
当我尝试使用简单的grep或awk时,
Adi:~ adi$ awk '/GET/, /HTTP/' serverlogs.txt
Run Code Online (Sandbox Code Playgroud)
它给出了
1.0.0.127.in-addr.arpa - - [10/Jun/2012 15:32:27] "GET /hello HTTP/1.1" 404 -
1.0.0.127.in-addr.arpa - - [10/Jun/2012 15:41:57] "GET /ss HTTP/1.1" 404 -
Run Code Online (Sandbox Code Playgroud)
我只想显示:你好和ss
有什么办法可以做到吗?
我正在编写一个python脚本,它将在从网页解析后提取脚本位置.可以说有两种情况:
<script type="text/javascript" src="http://example.com/something.js"></script>
Run Code Online (Sandbox Code Playgroud)
和
<script>some JS</script>
Run Code Online (Sandbox Code Playgroud)
我可以从第二个场景中获取JS,也就是在标签内部编写JS时.
但是有什么办法,我可以从第一个场景中获取src的值(即在脚本中提取src标签的所有值,例如http://example.com/something.js)
这是我的代码
#!/usr/bin/python
import requests
from bs4 import BeautifulSoup
r = requests.get("http://rediff.com/")
data = r.text
soup = BeautifulSoup(data)
for n in soup.find_all('script'):
print n
Run Code Online (Sandbox Code Playgroud)
输出:一些JS
我正在通过Python执行ADB命令,它在某种程度上工作正常.代码是:
#!/usr/bin/python
import sys
import string
import os
import subprocess
cmd = 'adb shell ls'
s = subprocess.Popen(cmd.split())
print "Again"
t = str(s)
for me in t.split('\n') :
print "Something"
print me[1]
Run Code Online (Sandbox Code Playgroud)
我得到的输出是:
static-243:Scripts adityagupta$ ./hellome.py
Again
Something
s
static-243:Scripts adityagupta$ config
cache
sdcard
acct
mnt
vendor
d
etc
ueventd.rc
ueventd.goldfish.rc
system
sys
sbin
proc
init.rc
init.goldfish.rc
init
default.prop
data
root
dev
Run Code Online (Sandbox Code Playgroud)
任何建议我可以使每个列表并存储其中的每个元素.列表应该是这样的
list = [cache,sdcard,acct,mnt,vendor ..]等等.