HTML页面到JSON到Asana任务

HTML页面到JSON到Asana任务,json,python-3.x,asana,Json,Python 3.x,Asana,嗨,我是Python新手,有几件事让我困扰。首先,我有我的脚本来做我想做的事情,但是不能让它在url中的所有项目(prod\u image\u wrap)中循环 from __future__ import print_function import requests import re import csv import asana from bs4 import BeautifulSoup as bs request = requests.get('url') content =

嗨,我是Python新手,有几件事让我困扰。首先,我有我的脚本来做我想做的事情,但是不能让它在url中的所有项目(prod\u image\u wrap)中循环

from __future__ import print_function
import requests
import re
import csv
import asana



from bs4 import BeautifulSoup as bs

request = requests.get('url')

content = request.content


soup = bs(content, 'html.parser')

i = soup.find_all('div', attrs = {'class': 'prod_image_wrap'})

for i in soup:


   title = soup.find('h1')

   product = soup.find('div', attrs = {'class': 'prod_name'})

   links = soup.find('div', 'prod_image')

   if links:
    for a in links.find_all('a', href=True):
        url = a['href']

elements = ("name:", title.string, "notes:", product.string, "PLink:", url)

dict = elements



import json
json_string = json.dumps(elements)

print (json_string)
html是:

    <title>TWEU-08.01.18-[4]-Lacoste_shoes</title>
   </head>
<body>
<h1>TWEU-08.01.18-[4]-Lacoste_shoes</h1>


    <div class="prod_image_wrap">
        <div class="prod_image">
            <a href="http://www.url.com/zzz/invisdescpage.html?pcode=WMK2SCB"><img src="http://img.url.com/watermark/rs.php?path=WMK2SCB-1.jpg&nw=130" alt="Wilson Kaos 2.0 SFT Camo Bk M's Shoe 9.0"  /></a>
        </div>
        <div class="prod_name">Wilson Kaos 2.0 SFT Camo Bk M's Shoe 9.0</div>
        <div class="prod_msrp">MSRP: $140,00</div>
        <div class="prod_price">$104,92</div>
        <div class="prod_price"><a href="#" onclick="window.open('http://www.url.com/360viewinvis.html?pcode=WMK2SCB','','width=530,height=480,location=no,menubar=no'); return false;" id="threesixtypop">360 View</a></div>
    </div>

    <div class="prod_image_wrap">
        <div class="prod_image">
            <a href="http://www.url.com/zzz/invisdescpage.html?pcode=LWSCEGW"><img src="http://img.url.com/watermark/rs.php?path=LWSCEGW-1.jpg&nw=130" alt="Lacoste Carnab Evo Gry/Wht Wom's Shoes 38.0"  /></a>
        </div>
        <div class="prod_name">Lacoste Carnab Evo Gry/Wht Wom's Shoes 38.0</div>
        <div class="prod_msrp">MSRP: $99,90</div>
        <div class="prod_price">$74,92</div>
        <div class="prod_price"><a href="#" onclick="window.open('http://www.url.com/360viewinvis.html?pcode=LWSCEGW','','width=530,height=480,location=no,menubar=no'); return false;" id="threesixtypop">360 View</a></div>
    </div>

    <div class="prod_image_wrap">
        <div class="prod_image">
            <a href="http://www.url.com/zzz/invisdescpage.html?pcode=LWCESWW"><img src="http://img.url.com/watermark/rs.php?path=LWCESWW-1.jpg&nw=130" alt="Lacoste Carnaby Evo White Wom's Shoes 38.0"  /></a>
        </div>
        <div class="prod_name">Lacoste Carnaby Evo White Wom's Shoes 38.0</div>
        <div class="prod_msrp">MSRP: $99,90</div>
        <div class="prod_price">$74,92</div>
        <div class="prod_price"><a href="#" onclick="window.open('http://www.url.com/360viewinvis.html?pcode=LWCESWW','','width=530,height=480,location=no,menubar=no'); return false;" id="threesixtypop">360 View</a></div>
    </div>
这就是我想要的,但只需要它循环,所以在这种情况下,将有3行。这样做的目的是将json变量分配给字段,并将其发送到Asana以创建一个任务,但我正在努力解决如何正确分配值的问题。请让我知道我是否走对了这条路

代码是:

import asana

client = asana.Client.basic_auth('key')
new_task = client.tasks.create_in_workspace("10568240677771",{"name":(dict['name:']), "notes":"This is a test created via API to begin auto transferring data\n\nhttps://example.com\n\nProduct Name 10.90\nhttps://example.com\n\nProduct Name 10.90\nhttps://example.com\n\n", "projects":"21543812277118", "due_on":"2018-09-23"})
我得到的错误是:

TypeError: tuple indices must be integers or slices, not str
TypeError: tuple indices must be integers or slices, not str