python 十六进制转中文_python 中十六进制如何转中文??

#!/usr/bin/env python

# -*- coding: utf-8 -*-

import requests,urllib2

from bs4 import BeautifulSoup

import sys

def get_img(url):

wb = requests.get(url)

wb.encoding = "utf-8"

soup = BeautifulSoup(wb.text,'lxml')

img_url = soup.select('#Zoom img')

if img_url == []:

return False

else:

return img_url[0].get('src')

def get_title(url):

wb = requests.get(url)

wb.encoding = "utf-8"

soup = BeautifulSoup(wb.text,'lxml')

title = soup.select("a[href='#']")

return title

def get_url(Url):

wb = requests.get(Url)

wb.encoding = 'gb2312'

soup = BeautifulSoup(wb.text,'lxml')

title = soup.select('.ulink')

url = soup.select('.ulink')

titles_urls = []

for x,y in zip(title,url):

reload(sys)

sys.setdefaultencoding('utf-8')

data = {

'title': x.get_text().split("《")[1].split("/")[0].split("》")[0],

'url':y.get('href'),

}

titles_urls.append(data)

return titles_urls

for z in range(1,100):

url = 'http://www.ygdy8.net/html/gndy/dyzz/list_23_%d.html' %z

for x in get_url(url):

u = get_img("http://www.ygdy8.net"+str(x['url']))

if u != False:

print u

print x['title']

y = str(x['title'])

with open('imgs/'+str(y)+'.jpg', "wb") as f:

f.write(requests.get(u).content)

print "第%d 页" %z

运行结果:

https://ws3.sinaimg.cn/mw690/81298caagw1f7mwfo0otfj21kw29ku0x.jpg

琼斯的自由国度

Traceback (most recent call last): with open('imgs/'+str(y)+'.jpg', "wb") as f:

IOError: [Errno 2] No such file or directory: 'imgs/\xe7\x90\xbc\xe6\x96\xaf\xe7\x9a\x84\xe8\x87\xaa\xe7\x94\xb1\xe5\x9b\xbd\xe5\xba\xa6.jpg'

[Finished in 0.7s with exit code 1]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值