<div id="con" class="bookyuanjiao">
content = soup.find("div", {"class": "bookyuanjiao", "id": "con"})
#!usr/bin/env
# -*-coding:utf-8 -*-
import urllib2
import os
from bs4 import BeautifulSoup as BS
import locale
import sys
from lxml import etree
import re
reload(sys)
sys.setdefaultencoding('gbk')
sub_folder = os.path.join(os.getcwd(), "sanguoyanyi")
if not os.path.exists(sub_folder):
os.mkdir(sub_folder)
path = sub_folder
# customize html as head of the articles
input = open(r'0.html', 'r')
head = input.read()
domain = 'http://www.shicimingju.com/book/sanguoyanyi.html'
t = domain.find(r'.html')
new_domain = '/'.join(domain.split("/")[:-2])
first_chapter_url = domain[:t] + "/" + str(1) + '.html'
print first_chapter_url
# Get url if chapter lists
req = urllib2.Request(url=domain)
resp = urllib2.urlopen(req)
html = resp.read()
soup = BS(html, 'lxml')
chapter_list = soup.find("div", {"class": "bookyuanjiao", "id": "mulu"})
sel = etree.HTML(str(chapter_list))
result = sel.xpath('//li/a/@href')
for each_link in result:
each_chapter_link = new_domain + "/" + each_link
print each_chapter_link
req = urllib2.Request(url=each_chapter_link)
resp = urllib2.urlopen(req)
html = resp.read()
soup = BS(html, 'lxml')
content = soup.find("div", {"class": "bookyuanjiao", "id": "con"})
title = soup.title.text
title = title.split(u'_《三国演义》_诗词名句网')[0]
html = str(content)
html = head + html + "</body></html>"
filename = path + "\\" + title + ".html"
print filename
# write file
output = open(filename, 'w')
output.write(html)
output.close()
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有