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用法的更多相关文章

  1. Python高级用法

    Python高级用法 三元表达式 x = 10 y = 20 print(x if x > y else y) x = 100 y = 20 print(x if x > y else y ...

  2. python zip文件密码爆破

    #!/usr/bin/env # coding=UTF-8 import zipfile import threading import os import sys class CrackZip: d ...

  3. Python高级用法总结

    Python很棒,它有很多高级用法值得细细思索,学习使用.本文将根据日常使用,总结介绍Python的一组高级特性,包括:列表推导式.迭代器和生成器.装饰器. 列表推导(list comprehensi ...

  4. python argparse用法总结

    转:python argparse用法总结 1. argparse介绍 argparse是python的一个命令行解析包,非常适合用来编写可读性非常好的程序. 2. 基本用法 prog.py是我在li ...

  5. Anaconda下载及安装及查看安装的Python库用法

    Anaconda下载及安装及查看安装的Python库用法 Anaconda 是一个用于科学计算的 Python 发行版,提供了包管理与环境管理的功能.Anaconda 利用 conda 来进行 pac ...

  6. python enumerate用法总结【转】

    enumerate()说明 enumerate()是python的内置函数 enumerate在字典上是枚举.列举的意思 对于一个可迭代的(iterable)/可遍历的对象(如列表.字符串),enum ...

  7. python zip函数(11)

    一.zip函数描述和使用 zip() 函数用于将可迭代的对象作为参数,将对象中对应的元素打包成一个个元组,然后返回由这些元组组成的对象,返回的结果可以直接强转为list列表,这样做的好处是节约了不少的 ...

  8. Python import用法以及与from...import的区别

    Python import用法以及与from...import的区别 在python用import或者from...import来导入相应的模块.模块其实就是一些函数和类的集合文件,它能实现一些相应的 ...

  9. 预备知识-python核心用法常用数据分析库(上)

    1.预备知识-python核心用法常用数据分析库(上) 目录 1.预备知识-python核心用法常用数据分析库(上) 概述 实验环境 任务一:环境安装与配置 [实验目标] [实验步骤] 任务二:Pan ...

随机推荐

  1. CISC和RISC的区别

    转载于http://blog.sina.com.cn/s/blog_9d5430ce0100x5pb.html RISC(Reduced Instruction Set Computer)和CISC( ...

  2. DEVOPS ROADMAP

  3. eclipse Maven Bootstrap 导航栏

    1.在pom.xml添加两个依赖 Bootstrap 依赖和jQuery依赖 代码如下 <!-- https://mvnrepository.com/artifact/org.webjars/b ...

  4. JDBC ----- SQL 插入记录

    package demo; import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; ...

  5. createjs小游戏开发总结

    createjs缩放,html组件input的缩放,transform位置,缩放,字体的大小. 移动端横屏和竖屏幕旋转屏幕自适应,input弹出软键盘的原理和位置偏移,focus,blur弹出软键盘. ...

  6. [loj#2005][SDOI2017]相关分析 _线段树

    「SDOI2017」相关分析 题目链接:https://loj.ac/problem/2005 题解: 把上面的式子拆掉,把下面的式子拆掉. 发现所有的东西都能用线段树暴力维护. 代码: #inclu ...

  7. 【转帖】我以为我对Kafka很了解,直到我看了这篇文章

    我以为我对Kafka很了解,直到我看了这篇文章 2019-08-12 18:05 https://www.sohu.com/a/333235171_463994?spm=smpc.author.fd- ...

  8. [转帖]mysql8.0忘记密码如何操作?

    mysql8.0忘记密码如何操作? https://www.cnblogs.com/gspsuccess/p/11245314.html mark 一下 上次竟然不知道怎么弄. 很不幸,刚安装了MYS ...

  9. 洛谷 P2018 消息传递 题解

    题面 总体来说是一道从下往上的DP+贪心: 设f[i]表示将消息传给i,i的子树全部接收到所能消耗的最小时间: 那么对于i的所有亲儿子节点j,我们会贪心地先给f[j]大的人传递,然后次大..... 可 ...

  10. flask项目配置

    config.py: class Config(object): """项目的配置""" DEBUG = True SECRET_KEY = ...