python zip用法
import requests url = "https://magi.com/search" querystring = {"q":"堕却乡"} headers = {
'authority': "magi.com",
'pragma': "no-cache",
'cache-control': "no-cache,no-cache",
'upgrade-insecure-requests': "1",
'user-agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36",
'accept': "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
'referer': "https://magi.com/search?q=%E7%89%B9%E6%96%AF%E6%8B%89",
'accept-encoding': "gzip, deflate, br",
'accept-language': "zh-CN,zh;q=0.9",
'cookie': "acw_tc=7af6142615735221487104171e68298facdedf1e07add2205636582990",
'Postman-Token': "dda0d475-41b9-44b4-812a-6dd489fe19dd,64d3ddc4-7036-4c42-bff6-53dcbc065db2",
'Host': "magi.com",
'Connection': "keep-alive"
} response = requests.request("GET", url,
headers=headers,
params=querystring,
# verify=True
) # print(response.text)
import lxml.etree
taxt = lxml.etree.HTML(response.text)
cells=taxt.xpath("//main//div[@data-type='fact']//article[@class='fact']")
for cell in cells:
sop = cell.xpath(".//dl/dd//text()")
sop_url = cell.xpath(".//div/ul//ol//li//a//@href")
reliability = cell.xpath(".//div//span//text()")
import re reliability=re.findall("(\d{1,3})",reliability[0])[-1]
print(reliability,sop,sop_url) #
import requests url = "https://www.tuicool.com/articles/jiyEnq7" headers = {
# 'Connection': "keep-alive",
# 'Pragma': "no-cache",
# 'Cache-Control': "no-cache",
# 'Upgrade-Insecure-Requests': "1",
'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36",
# 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
# 'Referer': "https://magi.com/",
# 'Accept-Encoding': "gzip, deflate",
# 'Accept-Language': "zh-CN,zh;q=0.9",
# 'Cookie': "Hm_lvt_28af3b8ab090b6821eea60c696e82b96=1573539698,1573540931; Hm_lpvt_28af3b8ab090b6821eea60c696e82b96=1573540931; ALLYESID4=128D850DE1E5CFA6; wdcid=11576d250e703f68; wdses=274efe2ee2728bdc; zycna=XkZbSr7Ily0BAXPBvUrZ6/aL; wdlast=1573540932",
# 'Postman-Token': "3fb8dcac-17e0-431b-bc1e-209ab1e7c2dd,86d4a803-c79a-4949-ac91-1edd3323465e",
# 'Host': "www.ce.cn",
# 'cache-control': "no-cache"
}
spo=['特斯拉', '电池供应商', '松下']
import chardet
response = requests.request("GET", url, headers=headers)
response.encoding=chardet.detect((response.content))["encoding"]
# response.encoding="utf-8"
import lxml.etree
taxt = lxml.etree.HTML(response.text)
list_sentence=taxt.xpath("//body//text()")
import re
# for t in t_list:
# t = re.split("(。|!|?)",t)
# if len(t)>1:
# t = ["".join(i) for i in zip(t[0::2], t[1::2])]
# print(t)
spo_sentence = []
for sentence in list_sentence:
sentence_list = re.split("(。|!|?)", sentence)
if len(sentence_list) > 1:
sentence_list = ["".join(i) for i in zip(sentence_list[0::2], sentence_list[1::2])]
for sentence in sentence_list:
if spo[1]=="描述" or spo[1]=="标签" or spo[1]=="近义项":
if sentence.find(spo[0])!=-1 and sentence.find(spo[2])!=-1:
spo_sentence.append(sentence)
print(sentence)
else:
if sentence.find(spo[0])!=-1 and sentence.find(spo[1])!=-1 and sentence.find(spo[2])!=-1:
spo_sentence.append(sentence)
print(sentence)
if spo_sentence:
item = {
"spo_sentence": spo_sentence,
"spo": spo
}
print(item)
python zip用法的更多相关文章
- Python高级用法
Python高级用法 三元表达式 x = 10 y = 20 print(x if x > y else y) x = 100 y = 20 print(x if x > y else y ...
- python zip文件密码爆破
#!/usr/bin/env # coding=UTF-8 import zipfile import threading import os import sys class CrackZip: d ...
- Python高级用法总结
Python很棒,它有很多高级用法值得细细思索,学习使用.本文将根据日常使用,总结介绍Python的一组高级特性,包括:列表推导式.迭代器和生成器.装饰器. 列表推导(list comprehensi ...
- python argparse用法总结
转:python argparse用法总结 1. argparse介绍 argparse是python的一个命令行解析包,非常适合用来编写可读性非常好的程序. 2. 基本用法 prog.py是我在li ...
- Anaconda下载及安装及查看安装的Python库用法
Anaconda下载及安装及查看安装的Python库用法 Anaconda 是一个用于科学计算的 Python 发行版,提供了包管理与环境管理的功能.Anaconda 利用 conda 来进行 pac ...
- python enumerate用法总结【转】
enumerate()说明 enumerate()是python的内置函数 enumerate在字典上是枚举.列举的意思 对于一个可迭代的(iterable)/可遍历的对象(如列表.字符串),enum ...
- python zip函数(11)
一.zip函数描述和使用 zip() 函数用于将可迭代的对象作为参数,将对象中对应的元素打包成一个个元组,然后返回由这些元组组成的对象,返回的结果可以直接强转为list列表,这样做的好处是节约了不少的 ...
- Python import用法以及与from...import的区别
Python import用法以及与from...import的区别 在python用import或者from...import来导入相应的模块.模块其实就是一些函数和类的集合文件,它能实现一些相应的 ...
- 预备知识-python核心用法常用数据分析库(上)
1.预备知识-python核心用法常用数据分析库(上) 目录 1.预备知识-python核心用法常用数据分析库(上) 概述 实验环境 任务一:环境安装与配置 [实验目标] [实验步骤] 任务二:Pan ...
随机推荐
- DP————LIS(最长上升子序列)和LCS(最长公共子序列)问题
LIS问题 https://www.acwing.com/problem/content/898/ 思路:首先数组a中存输入的数(原本的数),开辟一个数组f用来存结果,最终数组f的长度就是最终的答案: ...
- 潜在语义分析 LSA
简单介绍 LSA和传统向量空间模型(vector space model)一样使用向量来表示词(terms)和文档(documents),并通过向量间的关系(如夹角)来判断词及文档间的关系:不同的是, ...
- teach-es6-1
------------------------------------------------------------------------字符串连接: 之前: var str=''; var s ...
- Lua字符串及模式匹配
字符类基础函数举例介绍: string.len( ‘string’ ) string.lower( ‘string’ ) string.upper( ‘string’ ) string.rep( ‘a ...
- [转帖]容器云之K8s自动化安装方式的选择
容器云之K8s自动化安装方式的选择 时间 2016-12-05 19:10:53 极客头条 原文 http://geek.csdn.net/news/detail/127426 主题 Kubern ...
- 20190507-学习dubbo有感于梁飞
“作为一名程序员,BAT肯定是大多数人都想进的,仿佛是一种情愫,就像学生时代的我们对清华北大的向往感觉一样.Dubbo团队中,其中主要负责人就是梁飞了,梁飞的经历还是蛮励志的.梁飞,花名虚极, 200 ...
- Centos删除多余的Linux内核
删除开机多余kernel(centos) yum update 命令会大范围升级,有时候linux内核也会升级,升级后开机画面就会出现多个内核供你选择,所有强迫症的我需要删除旧的 ⒈查看正在使用的内核 ...
- PAT B1028 人口普查(20)
课本AC代码 #include <cstdio> struct person { char name[10]; int yy, mm, dd; } oldest, youngest, le ...
- centos服务器之间相互挂载(samba)
前提:假设A服务器ip为:192.168.1.101 ,B服务器ip为:192.168.1.102现在要求把A服务器的/mnt/test 路径下的文件夹 共享到B服务器的/home/ceshi 下. ...
- CSM(Certified Scrum Master) 敏捷认证是什么?
Scrum 是用于开发和持续支持复杂产品的一个框架.Scrum 基于试验性过程控制理论,借鉴了精益思想.时间盒.模块化设计等,并完整地体现了敏捷宣言和敏捷原则.Scrum 采用一种迭代.增量式的方法来 ...