修改 hosts 后 chrome 谷歌浏览器访问域名不及时生效解决办法
在开发过程中,经常需要切换本地测试域名,涉及 http 与 https 的自动跳转。当修改 hosts 后,浏览器可能不立即生效,只能开无痕浏览,此时可以尝试通过Chrome设置来解决。
打开 chrome://net-internals/#sockets,点击 Flush socket pools ,然后刷新页面并重新输入网址。
这个方法能帮助开发者快速解决 hosts 配置更新不及时的问题。
生命不息,折腾不止,一个80后老猫的网络日常
在开发过程中,经常需要切换本地测试域名,涉及 http 与 https 的自动跳转。当修改 hosts 后,浏览器可能不立即生效,只能开无痕浏览,此时可以尝试通过Chrome设置来解决。
打开 chrome://net-internals/#sockets,点击 Flush socket pools ,然后刷新页面并重新输入网址。
这个方法能帮助开发者快速解决 hosts 配置更新不及时的问题。
Chrome 的登录用户在任务栏里的图标右上角会显示个人资料头像,隐藏办法:任务栏上空白处点右键 > 任务栏设置 > 任务栏行为 > 取消勾选“在任务栏应用上显示徽章”。
失业的打击就像一场毫无征兆的秋雨,打湿了曾经那个自命不凡地自己。人生的所有曲折似乎在此时此刻彼此呼应,而今天我的处境,可能也正是许多人正要面临的窘境。
对于我来说,失业不仅仅是经济上的挫折,更是一次被迫的自我审视。在经历从收入丰厚到陷入困顿的转变后,内心的煎熬远比金钱的缺乏更加难以承受。
即使已经读过无数“如何应对失业”的建议,但当失业真正发生在自己身上时,却都显得苍白无力。当面对家庭的琐事和压力,每天醒来发现生活依旧难题重重时,难免开始怀疑。
同时,现实不可能因你的积极心态而变好,也不会因为学习了新技能就马上能获得一个能养家糊口的工作。此时,可能会让你更加的怀疑人生。
未来的路该怎么走?甚至是,自己是否具备应对新挑战的能力?开始陷入无尽的自我怀疑中……
无论30岁还是40岁,人生各阶段都有不同的难关。尽管艰难,但往往只能靠自己一步步挺过来。你感到焦虑、迷茫的原因,或许在于失去经济来源带来的家庭压力,让生活变得更加艰难。失业切断了收入的来源,这是对任何人来说都难以承受的考验。
失业期间,你可能会怀疑自己的价值,担心未来,但请记得,这些情绪都是正常的。也许,失业未必完全是坏事。许多人在职场上看似忙碌,实则原地踏步,甚至不断退步。一直得过且过,逐渐失去斗志。而失业反倒可能成为一次新的开始。
尽管这是一个痛苦的过程,却也是促使我成长的必经之路。无论是创业,还是借助朋友的帮助,先解决眼前的燃眉之急。假如回顾人脉网络,发现周围的朋友并不可靠,甚至阻碍你前行,或许更深层的问题并不只是失业,而是要重新审视自己与他人关系的本质。
失业可能会带来沮丧和压力,但最令人绝望的并非失去工作,而是放弃寻找新的可能性。朋友,务必要坚持下去,竭尽全力地拯救自己,不管过程多么艰难,都不要轻易放弃。妥协和退缩只会让人困于泥潭,而充满勇气的挣扎才能带来希望和成长。
陌生的朋友,祝好。
在AI兴起之前,一直在用的代码,分享给盆友们~
Mozilla Readability.js 的 PHP 端口。解析 html(通常是新闻和文章)返回标题、作者、主图像和文本内容(最新版可用属性)。分析每个节点,给它们打分,并确定哪些是相关的,哪些可以丢弃。
算法原作者:https://github.com/mingcheng/php-readability/
算法新版:https://github.com/andreskrey/readability.php(该项目已经废弃)
算法最新版:https://github.com/fivefilters/readability.php

require 'Readability.php'; $html = "整个html页面"; $Readability = new Readability($html); $ReadabilityData = $Readability->getContent(); //var_dump($ReadabilityData); echo "<h1>".$ReadabilityData['title']."</h1>"; echo $ReadabilityData['content'];
Readability.php
class Readability {
// 保存判定结果的标记位名称
const ATTR_CONTENT_SCORE = "contentScore";
// DOM 解析类目前只支持 UTF-8 编码
const DOM_DEFAULT_CHARSET = "utf-8";
// 当判定失败时显示的内容
const MESSAGE_CAN_NOT_GET = "Readability was unable to parse this page for content.";
// DOM 解析类(PHP5 已内置)
protected $DOM = null;
// 需要解析的源代码
protected $source = "";
// 章节的父元素列表
private $parentNodes = array();
// 需要删除的标签
// Note: added extra tags from https://github.com/ridcully
private $junkTags = Array("style", "form", "iframe", "script", "button", "input", "textarea",
"noscript", "select", "option", "object", "applet", "basefont",
"bgsound", "blink", "canvas", "command", "menu", "nav", "datalist",
"embed", "frame", "frameset", "keygen", "label", "marquee", "link");
// 需要删除的属性
private $junkAttrs = Array("style", "class", "onclick", "onmouseover", "align", "border", "margin", "id", "contentScore");
/**
* 构造函数
* @param $input_char 字符串的编码。默认 utf-8,可以省略
*/
function __construct($source, $input_char = "utf-8") {
$this->source = $source;
// DOM 解析类只能处理 UTF-8 格式的字符
$source = mb_convert_encoding($source, 'HTML-ENTITIES', $input_char);
// 预处理 HTML 标签,剔除冗余的标签等
$source = $this->preparSource($source);
// 生成 DOM 解析类
$this->DOM = new DOMDocument('1.0', $input_char);
try {
//libxml_use_internal_errors(true);
// 会有些错误信息,不过不要紧 :^)
if (!@$this->DOM->loadHTML('<?xml encoding="'.Readability::DOM_DEFAULT_CHARSET.'">'.$source)) {
throw new Exception("Parse HTML Error!");
}
foreach ($this->DOM->childNodes as $item) {
if ($item->nodeType == XML_PI_NODE) {
$this->DOM->removeChild($item); // remove hack
}
}
// insert proper
$this->DOM->encoding = Readability::DOM_DEFAULT_CHARSET;
} catch (Exception $e) {
// ...
}
}
/**
* 预处理 HTML 标签,使其能够准确被 DOM 解析类处理
*
* @return String
*/
private function preparSource($string) {
// 剔除多余的 HTML 编码标记,避免解析出错
preg_match("/charset=([\w|\-]+);?/", $string, $match);
if (isset($match[1])) {
$string = preg_replace("/charset=([\w|\-]+);?/", "", $string, 1);
}
// Replace all doubled-up <BR> tags with <P> tags, and remove fonts.
$string = preg_replace("/<br\/?>[ \r\n\s]*<br\/?>/i", "</p><p>", $string);
$string = preg_replace("/<\/?font[^>]*>/i", "", $string);
// @see https://github.com/feelinglucky/php-readability/issues/7
// - from http://stackoverflow.com/questions/7130867/remove-script-tag-from-html-content
$string = preg_replace("#<script(.*?)>(.*?)</script>#is", "", $string);
return trim($string);
}
/**
* 删除 DOM 元素中所有的 $TagName 标签
*
* @return DOMDocument
*/
private function removeJunkTag($RootNode, $TagName) {
$Tags = $RootNode->getElementsByTagName($TagName);
//Note: always index 0, because removing a tag removes it from the results as well.
while($Tag = $Tags->item(0)){
$parentNode = $Tag->parentNode;
$parentNode->removeChild($Tag);
}
return $RootNode;
}
/**
* 删除元素中所有不需要的属性
*/
private function removeJunkAttr($RootNode, $Attr) {
$Tags = $RootNode->getElementsByTagName("*");
$i = 0;
while($Tag = $Tags->item($i++)) {
$Tag->removeAttribute($Attr);
}
return $RootNode;
}
/**
* 根据评分获取页面主要内容的盒模型
* 判定算法来自:http://code.google.com/p/arc90labs-readability/
* 这里由郑晓博客转发
* @return DOMNode
*/
private function getTopBox() {
// 获得页面所有的章节
$allParagraphs = $this->DOM->getElementsByTagName("p");
// Study all the paragraphs and find the chunk that has the best score.
// A score is determined by things like: Number of <p>'s, commas, special classes, etc.
$i = 0;
while($paragraph = $allParagraphs->item($i++)) {
$parentNode = $paragraph->parentNode;
$contentScore = intval($parentNode->getAttribute(Readability::ATTR_CONTENT_SCORE));
$className = $parentNode->getAttribute("class");
$id = $parentNode->getAttribute("id");
// Look for a special classname
if (preg_match("/(comment|meta|footer|footnote)/i", $className)) {
$contentScore -= 50;
} else if(preg_match(
"/((^|\\s)(post|hentry|entry[-]?(content|text|body)?|article[-]?(content|text|body)?)(\\s|$))/i",
$className)) {
$contentScore += 25;
}
// Look for a special ID
if (preg_match("/(comment|meta|footer|footnote)/i", $id)) {
$contentScore -= 50;
} else if (preg_match(
"/^(post|hentry|entry[-]?(content|text|body)?|article[-]?(content|text|body)?)$/i",
$id)) {
$contentScore += 25;
}
// Add a point for the paragraph found
// Add points for any commas within this paragraph
if (strlen($paragraph->nodeValue) > 10) {
$contentScore += strlen($paragraph->nodeValue);
}
// 保存父元素的判定得分
$parentNode->setAttribute(Readability::ATTR_CONTENT_SCORE, $contentScore);
// 保存章节的父元素,以便下次快速获取
array_push($this->parentNodes, $parentNode);
}
$topBox = null;
// Assignment from index for performance.
// See http://www.peachpit.com/articles/article.aspx?p=31567&seqNum=5
for ($i = 0, $len = sizeof($this->parentNodes); $i < $len; $i++) {
$parentNode = $this->parentNodes[$i];
$contentScore = intval($parentNode->getAttribute(Readability::ATTR_CONTENT_SCORE));
$orgContentScore = intval($topBox ? $topBox->getAttribute(Readability::ATTR_CONTENT_SCORE) : 0);
if ($contentScore && $contentScore > $orgContentScore) {
$topBox = $parentNode;
}
}
// 此时,$topBox 应为已经判定后的页面内容主元素
return $topBox;
}
/**
* 获取 HTML 页面标题
*
* @return String
*/
public function getTitle() {
$split_point = ' - ';
$titleNodes = $this->DOM->getElementsByTagName("title");
if ($titleNodes->length
&& $titleNode = $titleNodes->item(0)) {
// @see http://stackoverflow.com/questions/717328/how-to-explode-string-right-to-left
$title = trim($titleNode->nodeValue);
$result = array_map('strrev', explode($split_point, strrev($title)));
return sizeof($result) > 1 ? array_pop($result) : $title;
}
return null;
}
/**
* Get Leading Image Url
*
* @return String
*/
public function getLeadImageUrl($node) {
$images = $node->getElementsByTagName("img");
if ($images->length && $leadImage = $images->item(0)) {
return $leadImage->getAttribute("src");
}
return null;
}
/**
* 获取页面的主要内容(Readability 以后的内容)
*
* @return Array
*/
public function getContent() {
if (!$this->DOM) return false;
// 获取页面标题
$ContentTitle = $this->getTitle();
// 获取页面主内容
$ContentBox = $this->getTopBox();
//Check if we found a suitable top-box.
if($ContentBox === null)
throw new RuntimeException(Readability::MESSAGE_CAN_NOT_GET);
// 复制内容到新的 DOMDocument
$Target = new DOMDocument;
$Target->appendChild($Target->importNode($ContentBox, true));
// 删除不需要的标签
foreach ($this->junkTags as $tag) {
$Target = $this->removeJunkTag($Target, $tag);
}
// 删除不需要的属性
foreach ($this->junkAttrs as $attr) {
$Target = $this->removeJunkAttr($Target, $attr);
}
$content = mb_convert_encoding($Target->saveHTML(), Readability::DOM_DEFAULT_CHARSET, "HTML-ENTITIES");
// 多个数据,以数组的形式返回
return Array(
'lead_image_url' => $this->getLeadImageUrl($Target),
'word_count' => mb_strlen(strip_tags($content), Readability::DOM_DEFAULT_CHARSET),
'title' => $ContentTitle ? $ContentTitle : null,
'content' => $content
);
}
function __destruct() { }
}在使用Typecho时,文章浏览次数统计算是最常用到的功能,把下面这段代码加到主题 functions.php 中,直接调用即可。代码加入了Cookie防刷新,这样文章浏览次数更真实。
function get_views($archive) {
$db = Typecho_Db::get();
$cid = $archive->cid;
//添加 table.contents.views 字段
if (!array_key_exists('views', $db->fetchRow($db->select()->from('table.contents')))) {
$db->query('ALTER TABLE `'.$db->getPrefix().'contents` ADD `views` INT(10) DEFAULT 0;');
}
$row = $db->fetchRow($db->select('views')->from('table.contents')->where('cid = ?', $cid));
$views = (int)$row['views'];
if ($archive->is('single')) {
$cookie = Typecho_Cookie::get('extend_views');
$cookie = $cookie ? explode(',', $cookie) : array();
if (!in_array($cid, $cookie)) {
$db->query($db->update('table.contents')->rows(array('views' => $views+1))->where('cid = ?', $cid));
$views = $views+1;
array_push($cookie, $cid);
$cookie = implode(',', $cookie);
Typecho_Cookie::set('extend_views', $cookie);
}
}
echo $views == 0 ? '暂无阅读' :'阅读量:' . $views;
}调用代码:
<?php get_views($this) ?>