美文网首页
一个很奇怪的编码问题

一个很奇怪的编码问题

作者: 折花载酒z | 来源:发表于2019-04-21 13:24 被阅读0次

PHP调用python文件
python代码:
import requests
import json

class WeatherSpider(object):
def inti(self):
pass

def request(self, url):
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36',
        'Referer': 'http://www.weather.com.cn/weather40d/101060201.shtml'
    }
    return requests.get(url, headers=headers)

def create_url(self):
    year = '2016'
    for i in range(1, 2):
        month = str(i) if i > 9 else "0" + str(i)
        url = "http://d1.weather.com.cn/calendar_new/" + year + "/101060201_" + year + month + ".html"
        self.get_data(url)

def get_data(self, url):
    respone = self.request(url).content
    json_str = respone.decode(encoding='utf-8')[11:]
    weathers = json.loads(json_str)
    data = ""
    for weather in weathers:
        data = data + weather.get('date') + '星期' + weather.get('wk') + weather.get('hmax') + \
            weather.get('hmin') + weather.get('hgl') + "<br>"
    print(data)

if name == 'main':
jl_weather = WeatherSpider()
jl_weather.create_url()
输出:
20151227������-9-2117%
20151228����һ-9-2123%
20151229���ڶ�-9-2127%
20151230������-9-2223%
20151231������-9-2223%
20160101������-9-2217%
20160102������-9-2230%
20160103������-10-2223%
20160104����һ-10-2220%
20160105���ڶ�-10-2320%
20160106������-10-2323%
20160107������-10-2323%
20160108������-10-2317%
20160109������-10-2327%
20160110������-10-2320%
20160111����һ-10-2313%
20160112���ڶ�-10-2330%
20160113������-10-2413%
20160114������-10-2417%
20160115������-10-2413%
20160116������-10-2417%
20160117������-10-2420%
20160118����һ-10-2413%
20160119���ڶ�-10-2420%
20160120������-10-2423%
20160121������-10-2410%
20160122������-9-2427%
20160123������-9-2330%
20160124������-9-2323%
20160125����һ-9-2320%
20160126���ڶ�-9-2317%
20160127������-8-2323%
20160128������-8-2310%
20160129������-8-2323%
20160130������-8-2217%
20160131������-8-2227%
20160201����һ-7-2223%
20160202���ڶ�-7-2223%
20160203������-7-2217%
20160204������-7-217%
20160205������-6-2120%
20160206������-6-2127%

PHP代码:
header("Content-type: text/html; charset=utf-8");
// echo "my first php demo";
output = exec("python D:\php_tools\PHPTutorial\WWW\\test\py_scripts\hello.py"); //array = explode(",", output); // foreach (array as value) { // echovalue."</br>";
//}
//查看编码方式,输出显示
encode = mb_detect_encoding(output, array("ASCII","UTF8","GB2312","GBK","BIG5"));
echo encode; //然后将这个编码转为UTF-8output = mb_convert_encoding($output,'UTF-8','EUC-CN');

echo $output;
FireShot Capture 001 - - www.test.com.png

想要去掉开头的字符.......................

相关文章

  • 一个很奇怪的编码问题

    PHP调用python文件python代码:import requestsimport json class We...

  • ListView在removeFooterView时报java.

    这些天遇到一个很奇怪的问题,很奇怪的问题,很奇怪的问题。重要的事情要说三遍。奇怪的问题大都是在解决之间很奇怪,如果...

  • python3无法print中文的解决方案

    python 的编码问题很让人窝火,本来以为 python3 不会再遇到各种奇怪的编码问题,没想到又跳到一个大坑里...

  • Python各种奇怪的编码问题

    在前公司被强行按头用Python 2处理小语种,就经常碰到类似的错误 在代码前加下列语句即可 但是这并不是一个好的...

  • 很奇怪的问题(Chrome)

    感觉这个问题跟Chrome浏览器本身的一些策略有关。 在我写完登录页面后 准备美滋滋的登录验证下的时候,确一直卡在...

  • 解决lxml 解析非utf-8编码网页的方法

    编码问题是一个老问题了,python3中默认编码方式使utf-8,lxml默认解析方式也是utf-8,但是仍然有很...

  • 程序员编码首行缩进使用Tab键好还是空格好?

    每个程序员都有自己喜欢的编码风格以及编码习惯,那么,问题来了。 一个很常用也很简单的问题,让程序员分为两派。编程时...

  • 很奇怪的

    这两天,浑身没力气,晚上睡不着,早上醒不来。撞鬼了(怎么可能)。说说这两天的梦吧!前天晚上竟然梦到,和一男的睡一起...

  • 奇怪的很

    唔……你这人奇怪的很,心思比女人还难猜…… 你,好像每天都这么晚睡…… 这样下去可不行啊…… 身体是革命的本钱,唔...

  • 常见Code Review过程中发现的问题

    主要体现在两个方面,一个是编码习惯问题,另一个是编码质量的问题。编码习惯主要有日志编写、代码注释以及编码风格的问题...

网友评论

      本文标题:一个很奇怪的编码问题

      本文链接:https://www.haomeiwen.com/subject/hnodgqtx.html