瑙e��requests�峰��婧�浠g���朵腑��涔辩����棰�

瑙e��requests�峰��婧�浠g���朵腑��涔辩����棰�

��requests�峰��婧�浠g���讹�濡�����涓���缃�椤碉�灏卞���戒��虹�颁贡��锛�涓��㈡��浠ヤ腑�虫����缃�绔�涓轰�锛�

import requests

url = 'http://desk.zol.com.cn/meinv/'

r = requests.get(url)

print r.text

�ц�涓��㈣�涓�����浣�浼����颁腑���ㄥ���藉����涔辩����

print r.encoding

��杩�涓��㈢��浠g��浣�浼����颁�requests�峰���扮��缂�����ISO-8859-1锛���璇ョ�椤电��缂�����gb2312锛���浠ユ���板�烘�ョ��缂���灏遍�藉����涔辩��浜�锛��d�璇ュ�浣�瑙e�宠�涓���棰���锛�

�跺������灏�缂���璁句负gb2312�冲��锛�瀹��寸��浠g��濡�涓�锛�

import requests

url = 'http://desk.zol.com.cn/meinv/'

r = requests.get(url)

r.encoding = 'gb2312'

print r.text

��浜�绔ラ����娆㈢��content�ヨ�峰��婧�浠g��锛�濡����存�ュ�涓���浠g��涓���text�逛负content��璇�锛�浣�浼����拌�峰���扮��婧�浠g��渚��ф��涔辩��锛���浠ヤ��㈢��浠g��涓����ㄤ�content�瑰��峰��婧�浠g����

��杩�content�峰��婧�浠g����绔ラ����浠ョ��杩���锛�

import requests

from lxml import etree

url = 'http://desk.zol.com.cn/meinv/'

r = requests.get(url)

code = r.content.decode('gb2312')

print code

你可能感兴趣的:(瑙e��requests�峰��婧�浠g���朵腑��涔辩����棰�)