如何用Python实现网页正文的提取-创新互联

这篇文章主要介绍了如何用Python实现网页正文的提取的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇如何用Python实现网页正文的提取文章都会有所收获,下面我们一起来看看吧。

创新互联建站长期为上千余家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为船营企业提供专业的网站建设、成都网站设计船营网站改版等技术服务。拥有10多年丰富建站经验和众多成功案例,为您定制开发。

一个典型的新闻网页包括几个不同区域:

如何用Python实现网页正文的提取

新闻网页区域

我们要提取的新闻要素包含在:

  • 标题区域

  • meta数据区域(发布时间等)

  • 配图区域(如果想把配图也提取)

  • 正文区域

而导航栏区域、相关链接区域的文字就不属于该新闻的要素。

新闻的标题、发布时间、正文内容一般都是从我们抓取的html里面提取的。如果仅仅是一个网站的新闻网页,提取这三个内容很简单,写三个正则表达式就可以完美提取了。然而,我们的爬虫抓来的是成百上千的网站的网页。对这么多不同格式的网页写正则表达式会累死人的,而且网页一旦稍微改版,表达式可能就失效,维护这群表达式也是会累死人的。

累死人的做法当然想不通,我们就要探索一下好的算法来实现。

1. 标题的提取

标题基本上都会出现在html的</code>标签里面,但是又被附加了诸如频道名称、网站名称等信息;</p><p>标题还会出现在网页的“标题区域”。</p><p>那么这两个地方,从哪里提取标题比较容易呢?</p><p>网页的“标题区域”没有明显的标识,不同网站的“标题区域”的html代码部分千差万别。所以这个区域并不容易提取出来。</p><p>那么就只剩下<code><title></code>标签了,这个标签很容易提取,无论是正则表达式,还是lxml解析都很容易,不容易的是如何去除频道名称、网站名称等信息。</p><p>先来看看,<code><title></code>标签里面都是设么样子的附加信息:</p><ul><li><p><code>上海用“智慧”激活城市交通脉搏,让道路更安全更有序更通畅_浦江头条_澎湃新闻-The Paper</code></p></li><li><p><code>“沪港大学联盟”今天在复旦大学成立_教育_新民网</code></p></li><li><p><code>三亚老人脚踹司机致公交车失控撞墙 被判刑3年_社会</code></p></li><li><p><code>外交部:中美外交安全对话9日在美举行</code></p></li><li><p><code>进博会:中国行动全球瞩目,中国担当世界点赞_南方观澜_南方网</code></p></li><li><p><code>资本市场迎来重大改革 设立科创板有何深意?-新华网</code></p></li></ul><p>观察这些title不难发现,新闻标题和频道名、网站名之间都是有一些连接符号的。那么我就可以通过这些连接符吧title分割,找出最长的部分就是新闻标题了。</p><p>这个思路也很容易实现,这里就不再上代码了,留给小猿们作为思考练习题自己实现一下。</p><h3>2. 发布时间提取</h3><p>发布时间,指的是这个网页在该网站上线的时间,一般它会出现在正文标题的下方——meta数据区域。从html代码看,这个区域没有什么特殊特征让我们定位,尤其是在非常多的网站版面面前,定位这个区域几乎是不可能的。这需要我们另辟蹊径。<br/>跟标题一样,我们也先看看一些网站的发布时间都是怎么写的:</p><ul><li><p>央视网2018年11月06日 22:22</p></li><li><p>时间:2018-11-07 14:27:00</p></li><li><p>2018-11-07 11:20:37 来源: 新华网</p></li><li><p>来源:中国日报网 2018-11-07 08:06:39</p></li><li><p>2018年11月07日 07:39:19</p></li><li><p>2018-11-06 09:58 来源:澎湃新闻</p></li></ul><p>这些写在网页上的发布时间,都有一个共同的特点,那就是一个表示时间的字符串,年月日时分秒,无外乎这几个要素。通过正则表达式,我们列举一些不同时间表达方式(也就那么几种)的正则表达式,就可以从网页文本中进行匹配提取发布时间了。</p><p>这也是一个很容易实现的思路,但是细节比较多,表达方式要涵盖的尽可能多,写好这么一个提取发布时间的函数也不是那么容易的哦。小猿们尽情发挥动手能力,看看自己能写出怎样的函数实现。这也是留给小猿们的一道练习题。</p><h3>3. 正文的提取</h3><p>正文(包括新闻配图)是一个新闻网页的主体部分,它在视觉上占据中间位置,是新闻的内容主要的文字区域。正文的提取有很多种方法,实现上有复杂也有简单。本文介绍的方法,是结合老猿多年的实践经验和思考得出来的一个简单快速的方法,姑且称之为“节点文本密度法”。</p><p>我们知道,网页的html代码是由不同的标签(tag)组成了一个树状结构树,每个标签是树的一个节点。通过遍历这个树状结构的每个节点,找到文本最多的节点,它就是正文所在的节点。根据这个思路,我们来实现一下代码。</p><h4>3.1 实现源码</h4><pre>#!/usr/bin/env python3 #File: maincontent.py #Author: veelion import re import time import traceback import cchardet import lxml import lxml.html from lxml.html import HtmlComment REGEXES = {     'okMaybeItsACandidateRe': re.compile(         'and|article|artical|body|column|main|shadow', re.I),     'positiveRe': re.compile(         ('article|arti|body|content|entry|hentry|main|page|'          'artical|zoom|arti|context|message|editor|'          'pagination|post|txt|text|blog|story'), re.I),     'negativeRe': re.compile(         ('copyright|combx|comment|com-|contact|foot|footer|footnote|decl|copy|'          'notice|'          'masthead|media|meta|outbrain|promo|related|scroll|link|pagebottom|bottom|'          'other|shoutbox|sidebar|sponsor|shopping|tags|tool|widget'), re.I), } class MainContent:     def __init__(self,):         self.non_content_tag = set([             'head',             'meta',             'script',             'style',             'object', 'embed',             'iframe',             'marquee',             'select',         ])         self.title = ''         self.p_space = re.compile(r'\s')         self.p_html = re.compile(r'<html|</html>', re.IGNORECASE|re.DOTALL)         self.p_content_stop = re.compile(r'正文.*结束|正文下|相关阅读|声明')         self.p_clean_tree = re.compile(r'author|post-add|copyright')     def get_title(self, doc):         title = ''         title_el = doc.xpath('//title')         if title_el:             title = title_el[0].text_content().strip()         if len(title) < 7:             tt = doc.xpath('//meta[@name="title"]')             if tt:                 title = tt[0].get('content', '')         if len(title) < 7:             tt = doc.xpath('//*[contains(@id, "title") or contains(@class, "title")]')             if not tt:                 tt =  doc.xpath('//*[contains(@id, "font01") or contains(@class, "font01")]')             for t in tt:                 ti = t.text_content().strip()                 if ti in title and len(ti)*2 > len(title):                     title = ti                     break                 if len(ti) > 20: continue                 if len(ti) > len(title) or len(ti) > 7:                     title = ti         return title     def shorten_title(self, title):         spliters = [' - ', '–', '—', '-', '|', '::']         for s in spliters:             if s not in title:                 continue             tts = title.split(s)             if len(tts) < 2:                 continue             title = tts[0]             break         return title     def calc_node_weight(self, node):         weight = 1         attr = '%s %s %s' % (             node.get('class', ''),             node.get('id', ''),             node.get('style', '')         )         if attr:             mm = REGEXES['negativeRe'].findall(attr)             weight -= 2 * len(mm)             mm = REGEXES['positiveRe'].findall(attr)             weight += 4 * len(mm)         if node.tag in ['div', 'p', 'table']:             weight += 2         return weight     def get_main_block(self, url, html, short_title=True):         ''' return (title, etree_of_main_content_block)         '''         if isinstance(html, bytes):             encoding = cchardet.detect(html)['encoding']             if encoding is None:                 return None, None             html = html.decode(encoding, 'ignore')         try:             doc = lxml.html.fromstring(html)             doc.make_links_absolute(base_url=url)         except :             traceback.print_exc()             return None, None         self.title = self.get_title(doc)         if short_title:             self.title = self.shorten_title(self.title)         body = doc.xpath('//body')         if not body:             return self.title, None         candidates = []         nodes = body[0].getchildren()         while nodes:             node = nodes.pop(0)             children = node.getchildren()             tlen = 0             for child in children:                 if isinstance(child, HtmlComment):                     continue                 if child.tag in self.non_content_tag:                     continue                 if child.tag == 'a':                     continue                 if child.tag == 'textarea':                     # FIXME: this tag is only part of content?                     continue                 attr = '%s%s%s' % (child.get('class', ''),                                    child.get('id', ''),                                    child.get('style'))                 if 'display' in attr and 'none' in attr:                     continue                 nodes.append(child)                 if child.tag == 'p':                     weight = 3                 else:                     weight = 1                 text = '' if not child.text else child.text.strip()                 tail = '' if not child.tail else child.tail.strip()                 tlen += (len(text) + len(tail)) * weight             if tlen < 10:                 continue             weight = self.calc_node_weight(node)             candidates.append((node, tlen*weight))         if not candidates:             return self.title, None         candidates.sort(key=lambda a: a[1], reverse=True)         good = candidates[0][0]         if good.tag in ['p', 'pre', 'code', 'blockquote']:             for i in range(5):                 good = good.getparent()                 if good.tag == 'div':                     break         good = self.clean_etree(good, url)         return self.title, good     def clean_etree(self, tree, url=''):         to_drop = []         drop_left = False         for node in tree.iterdescendants():             if drop_left:                 to_drop.append(node)                 continue             if isinstance(node, HtmlComment):                 to_drop.append(node)                 if self.p_content_stop.search(node.text):                     drop_left = True                 continue             if node.tag in self.non_content_tag:                 to_drop.append(node)                 continue             attr = '%s %s' % (                 node.get('class', ''),                 node.get('id', '')             )             if self.p_clean_tree.search(attr):                 to_drop.append(node)                 continue             aa = node.xpath('.//a')             if aa:                 text_node = len(self.p_space.sub('', node.text_content()))                 text_aa = 0                 for a in aa:                     alen = len(self.p_space.sub('', a.text_content()))                     if alen > 5:                         text_aa += alen                 if text_aa > text_node * 0.4:                     to_drop.append(node)         for node in to_drop:             try:                 node.drop_tree()             except:                 pass         return tree     def get_text(self, doc):         lxml.etree.strip_elements(doc, 'script')         lxml.etree.strip_elements(doc, 'style')         for ch in doc.iterdescendants():             if not isinstance(ch.tag, str):                 continue             if ch.tag in ['div', 'h2', 'h3', 'h4', 'p', 'br', 'table', 'tr', 'dl']:                 if not ch.tail:                     ch.tail = '\n'                 else:                     ch.tail = '\n' + ch.tail.strip() + '\n'             if ch.tag in ['th', 'td']:                 if not ch.text:                     ch.text = '  '                 else:                     ch.text += '  '             # if ch.tail:             #     ch.tail = ch.tail.strip()         lines = doc.text_content().split('\n')         content = []         for l in lines:             l = l.strip()             if not l:                 continue             content.append(l)         return '\n'.join(content)     def extract(self, url, html):         '''return (title, content)         '''         title, node = self.get_main_block(url, html)         if node is None:             print('\tno main block got !!!!!', url)             return title, '', ''         content = self.get_text(node)         return title, content</pre><h4>3.2 代码解析</h4><p>跟新闻爬虫一样,我们把整个算法实现为一个类:MainContent。</p><p>首先,定义了一个全局变量: REGEXES。它收集了一些经常出现在标签的class和id中的关键词,这些词标识着该标签可能是正文或者不是。我们用这些词来给标签节点计算权重,也就是方法calc_node_weight()的作用。</p><p>MainContent类的初始化,先定义了一些不会包含正文的标签 self.non_content_tag,遇到这些标签节点,直接忽略掉即可。</p><p>本算法提取标题实现在get_title()这个函数里面。首先,它先获得<code><title></code>标签的内容,然后试着从<code><meta></code>里面找title,再尝试从<code><body></code>里面找id和class包含title的节点,最后把从不同地方获得的可能是标题的文本进行对比,最终获得标题。对比的原则是:</p><ul><li><p><code><meta></code>, <code><body></code>里面找到的疑似标题如果包含在<code><title></code>标签里面,则它是一个干净(没有频道名、网站名)的标题;</p></li><li><p>如果疑似标题太长就忽略</p></li><li><p>主要把<code><title></code>标签作为标题</p></li></ul><p>从<code><title></code>标签里面获得标题,就要解决标题清洗的问题。这里实现了一个简单的方法: clean_title()。</p><p>在这个实现中,我们使用了lxml.html把网页的html转化成一棵树,从body节点开始遍历每一个节点,看它直接包含(不含子节点)的文本的长度,从中找出含有最长文本的节点。这个过程实现在方法:get_main_block()中。其中一些细节,小猿们可以仔细体会一下。</p><p>其中一个细节就是,clean_node()这个函数。通过get_main_block()得到的节点,有可能包含相关新闻的链接,这些链接包含大量新闻标题,如果不去除,就会给新闻内容带来杂质(相关新闻的标题、概述等)。</p><p>还有一个细节,get_text()函数。我们从main block中提取文本内容,不是直接使用text_content(),而是做了一些格式方面的处理,比如在一些标签后面加入换行符合<code>\n</code>,在table的单元格之间加入空格。这样处理后,得到的文本格式比较符合原始网页的效果。</p><h3>爬虫知识点</h3><p>1. cchardet模块<br/>用于快速判断文本编码的模块</p><p>2. lxml.html模块<br/>结构化html代码的模块,通过xpath解析网页的工具,高效易用,是写爬虫的居家必备的模块。</p><p>3. 内容提取的复杂性<br/>我们这里实现的正文提取的算法,基本上可以正确处理90%以上的新闻网页。<br/>但是,世界上没有千篇一律的网页一样,也没有一劳永逸的提取算法。大规模使用本文算法的过程中,你会碰到奇葩的网页,这个时候,你就要针对这些网页,来完善这个算法类。</p><p>关于“如何用Python实现网页正文的提取”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“如何用Python实现网页正文的提取”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注创新互联-成都网站建设公司行业资讯频道。</p> <br> 名称栏目:如何用Python实现网页正文的提取-创新互联 <br> 网页URL:<a href="http://lszwz.com/article/dccojj.html">http://lszwz.com/article/dccojj.html</a> </div> </div> <div class="other"> <h3>其他资讯</h3> <ul> <li> <a href="/article/epgjgi.html">itunes备份设置,itunes怎么设置备份</a> </li><li> <a href="/article/epgjhe.html">机箱用什么好,机箱里面有什么部件</a> </li><li> <a href="/article/epgjdg.html">域名申请机构,2域名注册流程如何进行?</a> </li><li> <a href="/article/epgpeh.html">模版网站是什么意思,无线鼠标双模版是什么意思</a> </li><li> <a href="/article/epgpee.html">怎么做一个帮助中心,产品帮助中心怎么做</a> </li> </ul> </div> </div> <div class="f_service_con"> <div class="h_fumin"> <div class="h_fumin_lei"> <div class="h_fumin_lei_tu"><img src="/Public/Home/images/f_service01.png"></div> <p>售后响应及时</p><span>7×24小时客服热线</span> </div> <div class="h_fumin_lei"> <div class="h_fumin_lei_tu"><img src="/Public/Home/images/f_service02.png"></div> <p>数据备份</p><span>更安全、更高效、更稳定</span> </div> <div class="h_fumin_lei"> <div class="h_fumin_lei_tu"><img src="/Public/Home/images/f_service03.png"></div> <p>价格公道精准</p><span>项目经理精准报价不弄虚作假</span> </div> <div class="h_fumin_lei"> <div class="h_fumin_lei_tu"><img src="/Public/Home/images/f_service04.png"></div> <p>合作无风险</p><span>重合同讲信誉,无效全额退款</span> </div> </div> </div> <div class="footerbar"> <div class="footer-t"> <div class="f-box"> <div class="f-1"> <div class="f-t"> <h2>联系我们</h2> <span>TEL</span> </div> <div class="f-b"> <h1><a href="tel:13518219792" rel="nofollow">135-1821-9792</a></h1> <h1><a href="tel:028-86922220" rel="nofollow">028-86922220</a></h1> <p>地址:乐山市太升南路288号锦天国际</p> </div> </div> <div class="f-2"> <div class="f-t"> <h2>快捷导航</h2> <span>Shortcut</span> </div> <div class="f-b"> <ul > </ul> <ul > <li><a href="/jianshe" title="乐山网站建设">乐山网站建设</a></li> <li><a href="/jianshe#ym_websiteBox2" title="品牌网站建设">品牌网站建设</a></li> <li><a href="/jianshe#ym_websiteBox1" title="企业网站建设">企业网站建设</a></li> <li><a href="/jianshe#ym_websiteBox4" title="集团网站建设">集团网站建设</a></li> <li><a href="/jianshe#ym_websiteBox4_2" title="外贸网站建设">外贸网站建设</a></li> <li><a href="/jianshe#ym_websiteBox4_5" title="企业宣传视频">企业宣传视频</a></li> </ul> <ul > <li><a href="/weixin" title="微信开发">微信开发</a></li> <li><a href="/weixin#item1" title="公众号开发">公众号开发</a></li> <li><a href="/weixin#item2" title="微商城建设">微商城建设</a></li> <li><a href="/weixin#item3" title="微官网建设">微官网建设</a></li> <li><a href="/weixin#item4" title="小程序开发">小程序开发</a></li> </ul> <ul> <li><a href="/case/" title="网站作品案例">网站作品案例</a></li> <li><a href="/case/" title="品牌网站案例">品牌网站案例</a></li> <li><a href="/case/" title="集团网站案例">集团网站案例</a></li> <li><a href="/case/" title="企业网站案例">企业网站案例</a></li> <li><a href="/case/" title="外贸网站案例">外贸网站案例</a></li> <li><a href="/case/" title="营销网站案例">营销网站案例</a></li> </ul> <ul style="margin:0;"> <li><a href="/about/">小谭建站</a></li> <li><a href="/about/">公司简介</a></li> <li><a href="/about#ab_item3">企业文化</a></li> <li><a href="/contact">联系我们</a></li> <li><a href="/Pay.html">付款方式</a></li> <li><a href="/jianshe#ym_websiteBox8">售后服务</a></li> </ul> <div style="clear:both;"></div> </div> </div> <div class="f-3"> <div class="f-t"> <h2>二维码</h2> <span>QR CODE</span> </div> <div class="f-b"> <ul> <li><img src="/Public/Home/images/fewm.png"> <p>微信公众号</p> </li> <li style="margin: 0"><img src="/Public/Home/images/fewm2.png"> <p>手机端网站</p> </li> <div style="clear:both;"></div> </ul> </div> </div> <div style="clear:both;"></div> </div> </div> <div class="footer-about"> <div class="w1200">乐山小谭建站工作室是一家专注从事于高品质视觉体验及互联网设计开发,<a href="/" target="_blank">乐山网站建设</a>,<a href="/jianshe" target="_blank">乐山网站设计</a>,<a href="/jianshe" target="_blank">乐山网页设计</a>,<a href="/jianshe" target="_blank">乐山网站制作</a>,<a href="/jianshe#ym_websiteBox2" target="_blank">品牌网站建设</a>,<a href="/jianshe#ym_websiteBox3" target="_blank">营销网站建设</a>,<a href="/jianshe#ym_websiteBox4" target="_blank">集团网站建设</a>,<a href="/jianshe#ym_websiteBox1" target="_blank">企业网站建设</a>,<a href="/jianshe#ym_websiteBox4_2" target="_blank">外贸网站建设</a>,<a href="/jianshe#ym_websiteBox4_3" target="_blank">响应式网站建设</a>,<a href="/weixin#item4" target="_blank">小程序开发</a>,<a href="/weixin" target="_blank">微信开发</a>,<a href="/jianshe#ym_websiteBox4_4" target="_blank">企业形象设计</a>,<a href="/jianshe#ym_websiteBox4_5" target="_blank">企业宣传视频</a>等服务,小谭建站位于乐山市龙岗区大运软件小镇,小谭建站拥有经验丰富的高级网站建设工程师和一流的网页高端设计人员,具备各种规模与类型网站建设的雄厚实力,在网站建设领域树立了自己独特的设计风格。 </div> <div class="friend-links"> <h6 class="clearfix"> <span class="tilte">友情链接</span> <a class="exchagne" href="http://wpa.qq.com/msgrd?v=3&uin=631063699&site=qq&menu=yes">交换友情链接</a> </h6> <div class="link-list clearfix"> <div class="link-slider"> <a href="http://www.75091.cn/" title="德信企业管理" target="_blank">德信企业管理</a>   <a href="http://www.76089.cn/" title="成都翻译公司" target="_blank">成都翻译公司</a>   <a href="http://m.cdcxhl.com/" title="成都网站设计" target="_blank">成都网站设计</a>   <a href="http://chengdu.cdcxhl.com/weixin/" title="微信公众号二次开发" target="_blank">微信公众号二次开发</a>   <a href="http://www.pzhzwz.com/" title="攀枝花网站设计" target="_blank">攀枝花网站设计</a>   <a href="http://www.cqcxhl.com/miniprogram/" title="小程序开发" target="_blank">小程序开发</a>   <a href="http://www.cxjianzhan.com/" title="网站推广" target="_blank">网站推广</a>   <a href="http://chengdu.cdcxhl.cn/dingzhi/" title="成都定制网站建设" target="_blank">成都定制网站建设</a>   <a href="http://www.emts.com.cn/about/" title="东方电机技改服务有限公司" target="_blank">东方电机技改服务有限公司</a>   <a href="http://www.jinhuajc.com/" title="橡塑保温板" target="_blank">橡塑保温板</a>    </div> </div> </div> </div> <div class="footer-b"> <div class="f-box"> <ul> <li><a href="/jianshe#ym_websiteBox6" target="_blank">服务流程</a></li> <li><a href="/jianshe#ym_websiteBox8" target="_blank">售后服务</a></li> <li><a href="/about/" target="_blank">联系我们</a></li> <li><a href="#" target="_blank">付款方式</a></li> <li><a href="#" target="_blank">网站地图</a></li> <li><a href="#" target="_blank">sitemap</a></li> <li> <p> <script data-cfasync="false" src="/Public/Home/js/email-decode.min.js"></script> </p> </li> <div style="clear:both;"></div> </ul> <p class="copy">Copyright © 2022 青羊区小谭信息技术咨询服务工作室 乐山建站工作室 All Rights Reserved   <a href="http://www.miibeian.gov.cn/" target="_blank" rel="nofollow">蜀ICP备2021004003号-25</a> <a style="display:none" target="_blank" href="###"><img style="vertical-align:middle" border="0" src="" width="65" height="25" /></a> </p> <div style="clear:both;"></div> </div> </div> <div class="sj_footer"> <div class="f-box"> <ul> <li><a href="/jianshe" target="_blank">网站建设</a></li> <li><a href="/jianshe#ym_websiteBox6" target="_blank">服务流程</a></li> <li><a href="/jianshe#ym_websiteBox8" target="_blank">售后服务</a></li> <li><a href="#" target="_blank">付款方式</a></li> <li><a href="/about/" target="_blank">关于我们</a></li> <li><a href="#" target="_blank">网站地图</a></li> <div style="clear:both;"></div> </ul> <p class="copy">Copyright © 2022 青羊区小谭信息技术咨询服务工作室 乐山建站工作室 </p> <p class="copy"> <a href="http://www.miibeian.gov.cn/" target="_blank" rel="nofollow">蜀ICP备2021004003号-25</a>  <a href="###" target="_blank"><img src="/Public/Home/images/govicon.gif" width="20" height="28" border="0" style="border-width:0px;border:hidden; border:none;"></a></p> <div style="clear:both;"></div> </div> </div> </div> <script type='text/javascript' src='/Public/Home/js/qqkefu.js'></script> <div class="qqkefu"> <ul> <li class="qq_czaa" id="130"><b class="a"></b>135-1821-9792</li> <li class="qq_czaa" id="130"><a href="tencent://message/?uin=1683211881"><b class="b"></b>业务咨询QQ</a></li> <li class="qq_czaa" id="130"><a href="javascript:showDiv()"><b class="f"></b>提交合作意向表</a></li> <li class="qq_czb"> <b class="c"></b> <div class="erweima"> <p><img src="/Public/Home/images/right_erweima.png"></p> </div> </li> <li class="top"><span></span></li> </ul> </div> <div id="popDiv" class="mydiv" style="display:none;"> <a class="mydiv_clk" href="javascript:closeDiv()">X</a> <div class="mydiv_list"> <div class="c_f_title"><span class="c_f_t">合作意向表</span></div> <div class="c_f_con"> <form id="form1" name="form1" class="mess_form" method="post" action="/post_order"> <input name='enews' type='hidden' value='AddFeedback'> <input name="bid" value="1" type="hidden"> <input type="hidden" name="ecmsfrom" value="9"> <input type="hidden" name='title' value="客户提交需求"> <li class="c_n"><span>公司名称</span> <dl><input name='gsname' id='gsname' type="text"></dl> </li> <li class="c_n"><span>邮箱</span> <dl><input name='gemail' id='gemail' type="text"></dl> </li> <li class="c_n xmm"> <div class="xmm_01"><span>姓名</span> <dl class="c_n_i"><input name='name' id='name' type="text"></dl> </div> <div class="xmm_01"><span style="text-align:center">电话</span> <dl class="c_n_i"><input name="tel" type="text"></dl> </div> </li> <li class="c_tser">您需要的服务</li> <li class="clearfix"> <dd><label><input type="radio" name='hobby' id='hobby' value="高端网站建设"><span>高端网站建设</span></label></dd> <dd><label><input type="radio" name='hobby' id='hobby' value="我需要做微信营销"><span>我需要做微信营销</span></label></dd> <dd><label><input type="radio" name='hobby' id='hobby' value="要找长期合作,需要年度服务"><span>要找长期合作,需要年度服务</span></label></dd> <dd><label><input type="radio" name='hobby' id='hobby' value="我需要做购物商城"><span>我需要做购物商城</span></label></dd> <dd><label><input type="radio" name='hobby' id='hobby' value="我需要网站改版"><span>我需要网站改版</span></label></dd> <dd><label><input type="radio" name='hobby' id='hobby' value="其他"><span>其他</span></label></dd> </li> <li class="c_tser">您关注的地方</li> <li class="clearfix"> <dd><label><input type="radio" name='hobby2' id='hobby2' value="对功能要求比较高"><span>对功能要求比较高</span></label></dd> <dd><label><input type="radio" name='hobby2' id='hobby2' value="对设计创意要求比较高"><span>对设计创意要求比较高</span></label></dd> <dd><label><input type="radio" name='hobby2' id='hobby2' value="需要可以购物支付"><span>需要可以购物支付</span></label></dd> <dd><label><input type="radio" name='hobby2' id='hobby2' value="搜索引擎排名"><span>搜索引擎排名</span></label></dd> </li> <li class="c_tser">预算</li> <li class="clearfix clearfix2"> <dd><label><input type="radio" name='hobby3' id='hobby3' value="一万以内"><span>一万以内</span></label> </dd> <dd><label><input type="radio" name='hobby3' id='hobby3' value="1-3万"><span>1-3万</span></label> </dd> <dd><label><input type="radio" name='hobby3' id='hobby3' value="3-5万"><span>3-5万</span></label> </dd> <dd><label><input type="radio" name='hobby3' id='hobby3' value="5万以上"><span>5万以上</span></label> </dd> <dd><label><input type="radio" name='hobby3' id='hobby3' value="需招投标"><span>需招投标</span></label> </dd> </li> <li class="c_n" style="border-top:1px solid #eee; padding-top:10px"><span>验证码</span> <dl class="c_n_i yzmm"><input type="text" name='code' id='code' value=""></dl><span style="text-align:center"><img src="/Public/Home/images/1661eb19783442c38063791555cd0d80.gif" onclick="this.src=this.src + '?'" width="100" height="40"></span> </li> <li class="clearfix"> <dd class="submit"><input name='submit' type="submit" value="提交需求"></dd> </li> </form> </div> </div> </div> <div id="bg" class="bg" style="display:none;"></div> <div id='popIframe' class='popIframe' frameborder='0'></div> <script> //提交需求选项 $(document).ready(function (e) { $(".mess_form").submit(function () { if ($("#gsname").val() == "") { alert("请填写您的公司名称!"); $("#gsname").focus(); return false; } if ($("#gemail").val() == "") { alert("请填写您的邮箱"); $("#gemail").focus(); return false; } if ($("#name").val() == "") { alert("请填写您的姓名!"); $("#name").focus(); return false; } if ($("#tel").val() == "") { alert("请填写您的电话!"); $("#tel").focus(); return false; } if ($("#hobby").val() == "") { alert("请选择您需要的服务!"); $("#hobby").focus(); return false; } if ($("#hobby2").val() == "") { alert("请选择您关注的地方!"); $("#hobby2").focus(); return false; } if ($("#hobby3").val() == "") { alert("请选择您的预算!"); $("#hobby3").focus(); return false; } if ($("#code").val() == "") { alert("请填写正确的验证码!"); $("#code").focus(); return false; } }); }); </script> <script language="javascript" type="text/javascript"> //提交需求窗口 function showDiv() { document.getElementById('popDiv').style.display = 'block'; document.getElementById('popIframe').style.display = 'block'; document.getElementById('bg').style.display = 'block'; } function closeDiv() { document.getElementById('popDiv').style.display = 'none'; document.getElementById('bg').style.display = 'none'; document.getElementById('popIframe').style.display = 'none'; } </script> <script type="text/javascript" src="/Public/Home/js/scrolltopcontrol.js"></script> <script type="text/javascript" src="/Public/Home/js/su_new.js"></script> </body> </html> <script> $(".con img").each(function(){ var src = $(this).attr("src"); //获取图片地址 var str=new RegExp("http"); var result=str.test(src); if(result==false){ var url = "https://www.cdcxhl.com"+src; //绝对路径 $(this).attr("src",url); } }); window.onload=function(){ document.oncontextmenu=function(){ return false; } } </script>