在python中分割数据

时间:2018-11-08 06:22:47

标签: python

使用

的数据集
{"bottomQuarter":4.4,"topQuarter":3.31,"median":3.8,"mean":4.03,"stddev":1.44,"moe":0.08,"good":2.59,"great":1.14,"poor":5.47,"bad":6.91,"best":0.2,"worst":15.98,"count":1121}

我想删除每个项目,即“ bottomQuarter”,并在将每个项目分配给变量时仅保留每个项目的编号。例如在python中具有bottomQuarter = 4.4 ...

当前显示AttributeError:“ Response”对象在尝试使用时没有属性“ split”

cigarAvg = req.split(",", 4)

此部分的完整资料是:

def grab_data(searchTerm):
    with requests.Session() as se:
        se.headers = {
            "X-Requested-With": "XMLHttpRequest",
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.92 Safari/537.36",
            "Referer": "https://herf.io/bids?search="+searchTerm,
            "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
            "Accept-Encoding":"gzip, deflate, br",
        }
        data = [
            "search="+searchTerm,
            "types=",
            "sites=",
        ]

        cookies = {
            "Cookie": "connect.sid=s%3ANYNh5s6LzCVWY8yE9Gra8lxj9OGHPAK_.vGiBmTXvfF4iDScBF94YOXFDmC80PQxY%2FX9FLQ23hYI"}

        url = "https://herf.io/bids/search/open"

        price = "https://herf.io/bids/search/stats"

        req = se.post(price,data="&".join(data),cookies=cookies,verify=False)
        str = req
        cigarAvg = str.split(",", 4)
        cigarBest = str.split(",", 10)
        cigarWorst = str.split(",", 11)

        splitResponse = req.split(",")
        print(req.text)
        return "Average: " + cigarAvg + " Best Price: " + cigarBest + " Worst Price: " + cigarWorst

0 个答案:

没有答案