腾讯新闻首页

企业服务 数据服务 案例ID:177553
春日微风
1 年经验· 北京阿提拉科技有限公司
微信扫码沟通,客服可协助直接对接工程师;如当前档期不合,也可继续推荐相似案例作者。

案例介绍

import requests
from lxml import etree
import re
def xiangqi(data):
html_=requests.get(data['link'])
# print(html_)charset=utf-8"
# print(html_.text)
cr=re.findall('charset="(.*?)"', html_.text)
c=cr.count('gbk')
if c<2:
html_.encoding='gbk'
else:
html_.encoding='utf8'


content=''.join(etree.HTML(html_.text).xpath('//p[@class="one-p"]//text()|//div[@class="content_area"]/p/text()')).replace('\n','')
if content:
return content

url='https://i.news.qq.com/trpc.qqnews_web.pc_base_srv.base_http_proxy/NinjaPageContentSync?pull_urls=news_top_2018'
source=requests.get(url).json()
data={}
for i in source['data']:
data['title']=i['title']
data['link']=i['url']
# print(data)
content=xiangqi(data)
data['content'] = content
print(data)

腾讯新闻首页

企业服务 · 数据服务 案例ID:177553
联系该工程师
微信扫码,建群沟通
作者: 春日微风 - 1年经验- 北京阿提拉科技有限公司

案例介绍

import requests
from lxml import etree
import re
def xiangqi(data):
html_=requests.get(data['link'])
# print(html_)charset=utf-8"
# print(html_.text)
cr=re.findall('charset="(.*?)"', html_.text)
c=cr.count('gbk')
if c<2:
html_.encoding='gbk'
else:
html_.encoding='utf8'


content=''.join(etree.HTML(html_.text).xpath('//p[@class="one-p"]//text()|//div[@class="content_area"]/p/text()')).replace('\n','')
if content:
return content

url='https://i.news.qq.com/trpc.qqnews_web.pc_base_srv.base_http_proxy/NinjaPageContentSync?pull_urls=news_top_2018'
source=requests.get(url).json()
data={}
for i in source['data']:
data['title']=i['title']
data['link']=i['url']
# print(data)
content=xiangqi(data)
data['content'] = content
print(data)

相似案例推荐

发布任务

企业点击发布任务,工程师会在任务下报名,招聘专员也会在 1 小时内与您联系确认。

1小时精推人才

需求方专属客服,免费梳理匹配

需求方客服微信二维码
扫码加微信 · 客服人工对接
更多案例
微信沟通 客服 看中这位工程师了?客服帮你 1 小时对接沟通 → ×