python爬取豆瓣出版社

用python爬取豆瓣所有出版社https://read.douban.com/provider/all
data=urllib.request.urlopen(‘https://read.douban.com/provider/all’).read()
print(type(data))

对数据格式进行转换
da=data.decode(‘utf-8’)
print(type(da))

import re
import urllib.request

pat='
(.*?)
' #正则表达式 data=urllib.request.urlopen('https://read.douban.com/provider/all').read() da=data.decode('utf-8') #对爬取的网页bytes格式转化为str rst=re.compile(pat).findall(str(da)) #写入文本中 f=open('F:/pytest/unit/prod.txt','w') for i in rst: f.write(i+'\n') #f.write('\n') print(rst) f.close()

你可能感兴趣的:(python爬取豆瓣出版社)