分为两部分问题,但也许一个回答另一个问题.我正试图从中得到一条信息
<div id="foo">
<div class="bar"><a data1="xxxx" data2="xxxx" href="http://foo.bar">Inner text"</a>
<div class="bar2"><a data3="xxxx" data4="xxxx" href="http://foo.bar">more text"</a>
Run Code Online (Sandbox Code Playgroud)
这是我现在正在使用的.
$articles = array();
$html=file_get_html('http://foo.bar');
foreach($html->find('div[class=bar] a') as $a){
$articles[] = array($a->href,$a->innertext);
}
Run Code Online (Sandbox Code Playgroud)
这非常适合从第一个div类中获取href和内部文本.我尝试在foreach中添加$ a-> data1,但这不起作用.
如何在抓取href和innertext的同时抓取那些内部数据标签.
还有一种方法可以让两个类都有一个语句吗?我假设我可以构建id的查找并获取所有div信息.
谢谢
基本上我用json编写了一个响应,并且无法弄清楚为什么它一直返回正确数量的数组成员但它们是空的.
$app->get('/api/server_list', function ($request, $response, $args) {
$serverlist = new ServerListing($this->db);
$servers = $serverlist->getServers();
$newResponse = $response->withJson($servers);
return $newResponse;
});
Run Code Online (Sandbox Code Playgroud)
这是上面的输出,添加了print_r($ servers)
[{},{}]Array
(
[0] => ServerEntity Object
(
[id:protected] => 1
[serverName:protected] => dc1.domain.com
)
[1] => ServerEntity Object
(
[id:protected] => 2
[serverName:protected] => dc2.domain.com
)
)
Run Code Online (Sandbox Code Playgroud)
以下是ServerListing的类代码:
<?php
class ServerListing extends Listing
{
public function getServers() {
$sql = "SELECT * from servers";
$stmt = $this->db->query($sql);
$results = [];
while($row = $stmt->fetch()) {
$results[] = new ServerEntity($row); …Run Code Online (Sandbox Code Playgroud) 如果在某处我得到了回答,我道歉,我找不到它.这取自preg_match的php参考.
<?php
// get host name from URL
preg_match('@^(?:http://)?([^/]+)@i',
"http://www.php.net/index.html", $matches);
$host = $matches[1];
// get last two segments of host name
preg_match('/[^.]+\.[^.]+$/', $host, $matches);
echo "domain name is: {$matches[0]}\n";
?>
Run Code Online (Sandbox Code Playgroud)
我理解除了@ ^和@i之外的所有这些.我已经搜索了大量的正则表达式引用,除了作为分隔符之外没有看到@符号的任何提及,这不是这里的情况.
谢谢
我希望这只是一件简单的事情.我正在尝试确定电子邮件是否已加密.
# Read e-mail from stdin
raw = sys.stdin.read()
raw_message = email.message_from_string( raw )
Run Code Online (Sandbox Code Playgroud)
我从http://docs.python.org/2/howto/regex.html上做了一个简单的匹配测试示例.
p = re.compile('-----BEGIN\sPGP\sMESSAGE-----')
m = p.match(raw)
if m:
log = open(cfg['logging']['file'], 'a')
log.write("THIS IS ENCRYPTED")
log.close()
else:
log = open(cfg['logging']['file'], 'a')
log.write("NOT ENCRYPTED:")
log.close()
Run Code Online (Sandbox Code Playgroud)
电子邮件已被阅读.日志文件被写入但它总是返回不匹配.我已经将raw写入日志文件并且该字符串存在.
不知道下一步该去哪里.
更新:这是raw(简单的测试消息)的输出
Sending email to: <bruce@packetaddiction.com>
Received: from localhost (localhost [127.0.0.1])
by mail2.packetaddiction.com (Postfix) with ESMTP id 5FE5D22A65
for <bruce@packetaddiction.com>; Tue, 10 Sep 2013 16:19:12 +0000 (UTC)
X-Virus-Scanned: Debian amavisd-new at mail2.packetaddiction.com
Received: from mail2.packetaddiction.com ([127.0.0.1])
by localhost …Run Code Online (Sandbox Code Playgroud)