Heim >Backend-Entwicklung >PHP-Tutorial >手把手教你做关键词匹配项目(搜索引擎)---- 第五天,教你做----_PHP教程
第五天
每快过一周的时候,都需要总结了,于老大也是这样告诫小帅帅的,每周周末前订好你下周的工作,并提供这周的总结给于老大。
主角是个程序员,一切都围绕小帅帅为中心开展这个项目为向导。
小帅帅 热衷于 技术,对技术的渴望要求是比较高的,他前期的技术是不咋地,但是他有很多优点,这些优点在后续的文章中会体现。
于老大 项目总监 ,他更倾向与培育人,所以他的沟通技巧是不一样的。
王总监,说出的话气势就是不一样,又能拉近关系,又能鼓励你卖命,还让你心甘情愿。
在这里面的角色,每个人的角色不一样,他们的沟通技巧都不一样,程序员在这里面有可能学到的是技术,项目经理有可能是学到的沟通技巧、待人处事以及如何培养值得信任的人。
言归正传:
小帅帅修炼了一个晚上,冒着黑眼圈,无精打采的回到公司,正好碰到于老大,兴奋的说到:于老大,昨天你给的那个PHP Simple HTML DOM Parser,我看了一个晚上终于弄明白了,等下把代码发给你,帮忙看看有没有问题?
于老大看着黑眼圈的小帅帅说到:你熬夜了,今天批你个假,好好休息,精神好了战斗力才会更强,下次注意下休息,别影响了第二天的工作。
小帅帅也觉得这样工作也不太好,就对于老大说: 谢谢于老大,下次会注意的,我等下把代码发给你,就回去休息。
于老大也不好再说什么了,只好答应到:好的。
淘宝里面关键词的HTML:
<span><</span><span>div </span><span>class</span><span>="search-hots"</span><span>><</span><span>a </span><span>href</span><span>="//s.taobao.com/search?spm=1.7274553.1997520241.1.z5UFkc&q=%B4%F3%C2%EB%C5%AE%D7%B0&refpid=420460_1006&source=tbsy&style=grid&tab=all"</span><span> data-spm-anchor-id</span><span>="1.7274553.1997520241.1"</span><span>></span>大码女装<span></</span><span>a</span><span>></span> <span><</span><span>a </span><span>href</span><span>="//s.taobao.com/search?spm=1.7274553.1997520241.2.z5UFkc&q=%C5%AE%D1%A9%B7%C4%C9%C0&refpid=420461_1006&source=tbsy&style=grid&tab=all"</span><span> data-spm-anchor-id</span><span>="1.7274553.1997520241.2"</span><span>></span>雪纺衫<span></</span><span>a</span><span>></span> <span><</span><span>a </span><span>href</span><span>="//s.taobao.com/search?spm=1.7274553.1997520241.3.z5UFkc&q=%C1%AC%D2%C2%C8%B9&refpid=420462_1006&source=tbsy&style=grid&tab=all"</span><span> class</span><span>="h"</span><span> data-spm-anchor-id</span><span>="1.7274553.1997520241.3"</span><span>></span>连衣裙<span></</span><span>a</span><span>></span> <span><</span><span>a </span><span>href</span><span>="//s.taobao.com/search?spm=1.7274553.1997520241.4.z5UFkc&q=%C5%AE%C1%B9%D0%AC&refpid=420463_1006&source=tbsy&style=grid&tab=all"</span><span> data-spm-anchor-id</span><span>="1.7274553.1997520241.4"</span><span>></span>女士凉鞋<span></</span><span>a</span><span>></span> <span><</span><span>a </span><span>href</span><span>="//s.taobao.com/search?spm=1.7274553.1997520241.5.z5UFkc&q=%C5%AE%B0%FC&refpid=420464_1006&source=tbsy&style=grid&tab=all"</span><span> data-spm-anchor-id</span><span>="1.7274553.1997520241.5"</span><span>></span>时尚女包<span></</span><span>a</span><span>></span> <span><</span><span>a </span><span>href</span><span>="//s.taobao.com/search?spm=1.7274553.1997520241.6.z5UFkc&q=%C5%AEt%D0%F4&refpid=420465_1006&source=tbsy&style=grid&tab=all"</span><span> data-spm-anchor-id</span><span>="1.7274553.1997520241.6"</span><span>></span>女士T恤<span></</span><span>a</span><span>></span> <span><</span><span>a </span><span>href</span><span>="//s.taobao.com/search?spm=1.7274553.1997520241.7.z5UFkc&q=%C4%D0t%D0%F4&refpid=420466_1006&source=tbsy&style=grid&tab=all"</span><span> data-spm-anchor-id</span><span>="1.7274553.1997520241.7"</span><span>></span>男士T恤<span></</span><span>a</span><span>></span> <span><</span><span>a </span><span>href</span><span>="//s.taobao.com/search?spm=1.7274553.1997520241.8.z5UFkc&q=%B7%C0%C9%B9%D2%C2&refpid=420467_1006&source=tbsy&style=grid&tab=all"</span><span> data-spm-anchor-id</span><span>="1.7274553.1997520241.8"</span><span>></span>防晒衣<span></</span><span>a</span><span>></span> <span><</span><span>a </span><span>href</span><span>="//s.taobao.com/search?spm=1.7274553.1997520241.9.z5UFkc&q=%C7%E9%C2%C2%D7%B0&refpid=430144_1006&source=tbsy&style=grid&tab=all"</span><span> data-spm-anchor-id</span><span>="1.7274553.1997520241.9"</span><span>></span>情侣装<span></</span><span>a</span><span>></span> <span><</span><span>a </span><span>href</span><span>="//s.taobao.com/search?spm=1.7274553.1997520241.10.z5UFkc&q=%B6%CC%BF%E3&refpid=430145_1006&source=tbsy&style=grid&tab=all"</span><span> data-spm-anchor-id</span><span>="1.7274553.1997520241.10"</span><span>></span>短裤<span></</span><span>a</span><span>></span> <span><</span><span>a </span><span>href</span><span>="//s.taobao.com/search?spm=1.7274553.1997520241.11.z5UFkc&q=%D3%BE%D2%C2&refpid=430146_1006&source=tbsy&style=grid&tab=all"</span><span> data-spm-anchor-id</span><span>="1.7274553.1997520241.11"</span><span>></span>泳衣<span></</span><span>a</span><span>></span> <span><</span><span>a </span><span>href</span><span>="//s.taobao.com/search?spm=1.7274553.1997520241.12.z5UFkc&q=%C4%D0%D0%AC&refpid=430147_1006&source=tbsy&style=grid&tab=all"</span><span> data-spm-anchor-id</span><span>="1.7274553.1997520241.12"</span><span>></span>新款男鞋<span></</span><span>a</span><span>></span> <span><</span><span>a </span><span>href</span><span>="//s.taobao.com/search?spm=1.7274553.1997520241.13.z5UFkc&q=%C1%B9%CF%AF&refpid=430148_1006&source=tbsy&style=grid&tab=all"</span><span> data-spm-anchor-id</span><span>="1.7274553.1997520241.13"</span><span>></span>凉席<span></</span><span>a</span><span>></span> <span><</span><span>a </span><span>href</span><span>="//s.taobao.com/search?spm=1.7274553.1997520241.14.z5UFkc&q=%B3%A4%C8%B9&refpid=430149_1006&source=tbsy&style=grid&tab=all"</span><span> data-spm-anchor-id</span><span>="1.7274553.1997520241.14"</span><span>></span>长裙<span></</span><span>a</span><span>></span> <span><</span><span>a </span><span>href</span><span>="//s.taobao.com/search?spm=1.7274553.1997520241.15.z5UFkc&q=%CD%CF%D0%AC&refpid=430150_1006&source=tbsy&style=grid&tab=all"</span><span> data-spm-anchor-id</span><span>="1.7274553.1997520241.15"</span><span>></span>拖鞋<span></</span><span>a</span><span>></span> <span><</span><span>a </span><span>class</span><span>="more more-with-border"</span><span> href</span><span>="http://top.taobao.com/index.php?spm=1.7274553.1997520241.16.z5UFkc&from=tbsy"</span><span> data-spm-anchor-id</span><span>="1.7274553.1997520241.16"</span><span>></span>更多<span><</span><span>i</span><span>><</span><span>em</span><span>></</span><span>em</span><span>><</span><span>span</span><span>></</span><span>span</span><span>></</span><span>i</span><span>></</span><span>a</span><span>></span> <span></</span><span>div</span><span>></span>
小帅帅的代码如下:
<?<span>php </span><span>$curl</span> = <span>new</span><span> ExtendedCurl(); </span><span>$content</span> = <span>$curl</span>->get("http://www.taobao.com"<span>); </span><span>if</span>(<span>$curl</span>-><span>hasError()){ </span><span>throw</span> <span>new</span> <span>Exception</span>(<span>$curl</span>->getError(), <span>$curl</span>-><span>getHttpCode()); } </span><span>$html</span> = str_get_html(<span>$content</span><span>); </span><span>foreach</span>(<span>$html</span>->find(".search-hots a[class!=more]") <span>as</span> <span>$ele</span><span>){ </span><span>$keywords</span>[] = <span>$ele</span>-><span>innertext; } </span><span>foreach</span>(<span>$keywords</span> <span>as</span> <span>$keyword</span><span>){ </span><span>//</span><span>save $keyword to database</span> ....<span> }</span>
小帅帅交了代码之后就回去安心的休息去了,睡着的时候做了个梦,梦里的内容少儿不宜,跳过....
就这样,小帅帅惊险的一周过了.....
现在 百度推广有精确、短语、广泛三种匹配方式,,一般来说黄金组合匹配方式是:广泛匹配+搜索词报告+否定关键词。流量来说的话就是 广泛>短语>精确啦,可以根据你们呢的实际情况进行设置!
如果要精确匹配,需要ABC都带引号。