当前位置:网站首页>起点中文网 字体反爬技术 网页可以显示数字字母 网页代码是乱码或空格
起点中文网 字体反爬技术 网页可以显示数字字母 网页代码是乱码或空格
2022-07-28 05:29:00 【ithicker】
我接过一段代码
# -*- coding: utf-8 -*-
""" Created on Tue Mar 23 14:38:01 2021 @author: xinyi """
import xlwt
import requests
from lxml import etree
import time
all_info_list = []
def get_info(url):
html = requests.get(url)
selector = etree.HTML(html.text)
infos = selector.xpath('//ul[@class="all-img-list cf"]/li')
for info in infos:
title = info.xpath('div[2]/h4/a/text()')[0]
author = info.xpath('div[2]/p[1]/a[1]/text()')[0]
style_1 = info.xpath('div[2]/p[1]/a[2]/text()')[0]
style_2 = info.xpath('div[2]/p[1]/a[3]/text()')[0]
style = style_1+'·'+style_2
complete = info.xpath('div[2]/p[1]/span/text()')[0]
introduce = info.xpath('div[2]/p[2]/text()')[0].strip()
word = info.xpath('div[2]/p[3]/span/text()')[0].strip('万字')
info_list = [title,author,style,complete,introduce,word]
all_info_list.append(info_list)
time.sleep(1)
if __name__ == '__main__':
urls = ['http://a.qidian.com/?page={}'.format(str(i)) for i in range(1,101)]
for url in urls:
get_info(url)
header = ['title','author','style','complete','introduce','word']
book = xlwt.Workbook(encoding='utf-8')
sheet = book.add_sheet('Sheet1')
for h in range(len(header)):
sheet.write(0, h, header[h])
i = 1
for list in all_info_list:
j = 0
for data in list:
sheet.write(i, j, data)
j += 1
i += 1
book.save('xiaoshuo.xls')

三. 最终代码
# -*- coding: utf-8 -*-
""" Created on Tue Mar 23 14:38:01 2021 @author: xinyi """
import xlwt
import requests
from lxml import etree
import time
all_info_list = []
def get_info(url):
html = requests.get(url)
selector = etree.HTML(html.text)
infos = selector.xpath('//ul[@class="all-img-list cf"]/li')
for info in infos:
title = info.xpath('div[2]/h4/a/text()')[0]
author = info.xpath('div[2]/p[1]/a[1]/text()')[0]
style_1 = info.xpath('div[2]/p[1]/a[2]/text()')[0]
style_2 = info.xpath('div[2]/p[1]/a[3]/text()')[0]
style = style_1+'·'+style_2
complete = info.xpath('div[2]/p[1]/span/text()')[0]
introduce = info.xpath('div[2]/p[2]/text()')[0].strip()
word = info.xpath('div[2]/p[3]/span/text()')[0].strip('万字')
info_list = [title,author,style,complete,introduce,word]
all_info_list.append(info_list)
time.sleep(1)
if __name__ == '__main__':
urls = ['http://a.qidian.com/?page={}'.format(str(i)) for i in range(1,101)]
for url in urls:
get_info(url)
header = ['title','author','style','complete','introduce','word']
book = xlwt.Workbook(encoding='utf-8')
sheet = book.add_sheet('Sheet1')
for h in range(len(header)):
sheet.write(0, h, header[h])
i = 1
for list in all_info_list:
j = 0
for data in list:
sheet.write(i, j, data)
j += 1
i += 1
book.save('xiaoshuo.xls')
四. 参考资料
边栏推荐
- MOOC翁恺C语言 第六周:数组与函数:1.数组2.函数的定义与使用3.函数的参数和变量4.二维数组
- Result number of filled briquettes
- 小甲鱼C(第五章循环控制结构程序567)break和continue语句
- DNS正向解析实验
- Network - network layer
- VSphere esxi 7.0 update 3 release notes
- Es6--- > arrow function, class, modularization
- [learning records of erudite Valley] Super summary, attentive sharing | collection
- JS four operations are repackaged to solve the problem of precision loss
- Network - transport layer (detailed version)
猜你喜欢

VLAN的配置

Repair the faulty sector

爬虫学习总结

DNS域名解析

Firewall - iptables firewall (four tables and five links, firewall configuration method, detailed explanation of matching rules)

一、PXE概述和安装

Clock tree analysis example

Shell script -- program conditional statements (conditional tests, if statements, case branch statements, echo usage, for loops, while loops)

VNC Timed out waiting for a response from the computer

MOOC翁恺C语言第七周:数组运算:1.数组运算2.搜索3.排序初步
随机推荐
Asynchronous programming promise
Repair the faulty sector
Traversal binary tree
SySeVR环境配置:joern-0.3.1、Neo4j-2.1.5、py2neo2.0
Small turtle C (Chapter 5 loop control structure program 567) break and continue statements
PXE unattended installation management
Esxi community nvme driver update v1.1
---Stack & queue---
SSH service configuration
MOOC Weng Kai C language week 6: arrays and functions: 1. Arrays 2. Definition and use of functions 3. Parameters and variables of functions 4. Two dimensional arrays
Array to linked list
Custom component -- communication between parent and child components
Blue Bridge Cup square filling number
Suger Bi create task
Esxi community network card driver updated again
shell脚本——sort、uniq、tr、数组排序、cut、eval命令配置
MOOC Weng Kai C language week 5: 1. cycle control 2. multiple cycles 3. cycle application
raid磁盘阵列
Servlet
MOOC翁恺C语言第五周:1.循环控制2.多重循环3.循环应用