python鐖櫕html涓枃涔辩爜瑙e喅鏂规

  • 瑙e喅鏂规锛屽鑾峰彇鐨刾age html浠g爜鍏堣繘琛宔ncode("GBK")锛岀劧鍚庡啀浣跨敤decode("utf-8")杩涜瑙g爜
  • 渚嬪瓙
#浣跨敤post鏂规硶鏉ユ彁浜ょ敤鎴峰悕鍜屽瘑鐮佺櫥闄� 
import urllib2
import urllib

url = 'http://www.dataguru.cn/member.php?mod=logging&action=login'
user_agent = 'Mozilla/5.0'  
values = {'username' : 'python鐖櫕',  'password' : '123456789' }  #璁剧疆璐﹀彿鍜屽瘑鐮�
data = urllib.urlencode(values)    #灏嗚处鍙峰拰瀵嗙爜缂栫爜鎴恥rl褰㈠紡
request = urllib2.Request(url,data)  
request.add_header("user-agent","Mozilla/5.0")
response = urllib2.urlopen(request)  
page = response.read().decode("GBK").encode("utf-8")
print(page)


你可能感兴趣的:(python鐖櫕html涓枃涔辩爜瑙e喅鏂规)