代码:
# -*- coding:utf-8 -*-
import chardet
import urllib, urllib2, sys, json, re, os, time, cgi
import string,time,datetime
import pymysql.cursors
reload(sys)
sys.setdefaultencoding('utf-8')
if __name__=='__main__':
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 5.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36'}
user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.24) Gecko/20111103 Firefox/3.6.24'
r = urllib2.Request("https://xin.baidu.com/index/recommendCompAjax?_="+str(long(time.time()*100)), headers=headers)
response = urllib2.urlopen(r)
page = response.read()
content = eval(page)
for val in content['data']:
print(val['pid'])
print val['name'].encode('utf-8').decode('unicode_escape')
代码执行结果:
xlTM-TogKuTw8WCD3fpSm0-xsvPsv9c3BQmd
苏州东菱振动试验仪器有限公司
xlTM-TogKuTwxSPWs2zQIA7DTsYXmb7aDgmd
佛山市南海高达建筑机械有限公司
xlTM-TogKuTw41qODqaHD0b3*dLDT*abdgmd
深圳市视显光电技术有限公司
xlTM-TogKuTw4RDxyg2mV80C2BYndUVzDgmd
上海东洲罗顿通信股份有限公司
xlTM-TogKuTwqc1vjmJ0D0*p6M0Qyjw9CAmd
深圳市汇深网信息科技有限公司
网友评论