python嵌套列表错误,ValueError:int()以10为底的无效文字:'beer'

问题描述 投票:0回答:1

我正在尝试遍历列表的嵌套列表并追加到列表中

    # def get_info(item_urls, count): #count is being passed in
    # for item in item_urls:
        #get data from current URL

        resp = s.get(url1, headers=headers, verify=False).text
        soup = bs(resp, 'html.parser')
        res = soup.find_all('table', attrs={'class': 'table table-striped-odd specification'})
        first = res[0]
        res1 = first.find_all('td')
        print(res1)
        for thing in res1:
            print(thing.text)
        table = [[] for i in range(0, count)]
        for thing in res1:
            # print(thing.text)
            table.append(thing.text)
            print(table)

抱歉,我应该给出真实的代码。这是我的回复:

Processor Type
1.0 GHz base frequency, up to 3.6 GHz with Intel® Turbo Boost Technology
Hard Drive Capacity
256 GB
Condition
New
Processor Speed
1 GHz
Manufacturer Part Number
8BD79UA#ABA
Wireless Technology
Realtek RTL8821CE 802.11b/g/n/ac (1x1) Wi-Fi and Bluetooth® 4.2 Combo (MU-MIMO supported)
RAM Memory
8 GB
Maximum RAM Supported
8 GB
Operating System
Windows 10
Model
14-dq1039wm
Screen Size
14"
Brand
HP
[[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], 'Processor Type']
[[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], 'Processor Type', '1.0 GHz base frequency, up to 3.6 GHz with Intel® Turbo Boost Technology']
[[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], 'Processor Type', '1.0 GHz base frequency, up to 3.6 GHz with Intel® Turbo Boost Technology', 'Hard Drive Capacity']
[[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], 'Processor Type', '1.0 GHz base frequency, up to 3.6 GHz with Intel® Turbo Boost Technology', 'Hard Drive Capacity', '256 GB']
[[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], 'Processor Type', '1.0 GHz base frequency, up to 3.6 GHz with Intel® Turbo Boost Technology', 'Hard Drive Capacity', '256 GB', 'Condition']
[[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], 'Processor Type', '1.0 GHz base frequency, up to 3.6 GHz with Intel® Turbo Boost Technology', 'Hard Drive Capacity', '256 GB', 'Condition', 'New']
[[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], 'Processor Type', '1.0 GHz base frequency, up to 3.6 GHz with Intel® Turbo Boost Technology', 'Hard Drive Capacity', '256 GB', 'Condition', 'New', 'Processor Speed']
[[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], 'Processor Type', '1.0 GHz base frequency, up to 3.6 GHz with Intel® Turbo Boost Technology', 'Hard Drive Capacity', '256 GB', 'Condition', 'New', 'Processor Speed', '1 GHz']
[[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], 'Processor Type', '1.0 GHz base frequency, up to 3.6 GHz with Intel® Turbo Boost Technology', 'Hard Drive Capacity', '256 GB', 'Condition', 'New', 'Processor Speed', '1 GHz', 'Manufacturer Part Number']
[[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], 'Processor Type', '1.0 GHz base frequency, up to 3.6 GHz with Intel® Turbo Boost Technology', 'Hard Drive Capacity', '256 GB', 'Condition', 'New', 'Processor Speed', '1 GHz', 'Manufacturer Part Number', '8BD79UA#ABA']
[[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], 'Processor Type', '1.0 GHz base frequency, up to 3.6 GHz with Intel® Turbo Boost Technology', 'Hard Drive Capacity', '256 GB', 'Condition', 'New', 'Processor Speed', '1 GHz', 'Manufacturer Part Number', '8BD79UA#ABA', 'Wireless Technology']
[[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], 'Processor Type', '1.0 GHz base frequency, up to 3.6 GHz with Intel® Turbo Boost Technology', 'Hard Drive Capacity', '256 GB', 'Condition', 'New', 'Processor Speed', '1 GHz', 'Manufacturer Part Number', '8BD79UA#ABA', 'Wireless Technology', 'Realtek RTL8821CE 802.11b/g/n/ac (1x1) Wi-Fi and Bluetooth® 4.2 Combo (MU-MIMO supported)']
[[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], 'Processor Type', '1.0 GHz base frequency, up to 3.6 GHz with Intel® Turbo Boost Technology', 'Hard Drive Capacity', '256 GB', 'Condition', 'New', 'Processor Speed', '1 GHz', 'Manufacturer Part Number', '8BD79UA#ABA', 'Wireless Technology', 'Realtek RTL8821CE 802.11b/g/n/ac (1x1) Wi-Fi and Bluetooth® 4.2 Combo (MU-MIMO supported)', 'RAM Memory']
[[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], 'Processor Type', '1.0 GHz base frequency, up to 3.6 GHz with Intel® Turbo Boost Technology', 'Hard Drive Capacity', '256 GB', 'Condition', 'New', 'Processor Speed', '1 GHz', 'Manufacturer Part Number', '8BD79UA#ABA', 'Wireless Technology', 'Realtek RTL8821CE 802.11b/g/n/ac (1x1) Wi-Fi and Bluetooth® 4.2 Combo (MU-MIMO supported)', 'RAM Memory', '8 GB']
[[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], 'Processor Type', '1.0 GHz base frequency, up to 3.6 GHz with Intel® Turbo Boost Technology', 'Hard Drive Capacity', '256 GB', 'Condition', 'New', 'Processor Speed', '1 GHz', 'Manufacturer Part Number', '8BD79UA#ABA', 'Wireless Technology', 'Realtek RTL8821CE 802.11b/g/n/ac (1x1) Wi-Fi and Bluetooth® 4.2 Combo (MU-MIMO supported)', 'RAM Memory', '8 GB', 'Maximum RAM Supported']

我想遍历数据并将其附加到嵌套表中,然后返回表

我不确定为什么我的清单不在

python list nested-lists
1个回答
0
投票

尝试此,IIUC

data = ["beer", "is", "awesome!", "...", "for", "helping", "my", "depression"]
count = len(data) # counting data for a number... that I should have just made up
table = []
for i in data:
    print(i)
    table.append([i])
    print(i, table)
for thing in table:
    print(thing)
© www.soinside.com 2019 - 2024. All rights reserved.