【问题标题】:Compare two lists in Python比较 Python 中的两个列表
【发布时间】:2012-05-04 03:23:28
【问题描述】:

所以这是我想要比较的代码。我想要做的是从路径目录中列出 appids,这是可行的。然后我试图去一个网站(f)。并解析 html 页面并获取该站点上列出的 appid。

我想要做的是从本地系统获取 appid,搜索 f(来自站点的应用程序 ID),然后返回 appid 是什么。

当我打印 appid 时:

D:\python>jump_me.py |more
1b4dd67f29cb1962
28c8b86deab549a1
431a5b43435cc60b
4975d6798a8bdf66
7e4dca80246863e3
8eafbd04ec8631
9b9cdc69c1c24e2b
bc03160ee1a59fc1

当我打印 f,这是我从网上得到的解析数据:

65009083bfa6a094 | (app launched via XPMode) |
469e4a7982cea4d4 | ? (.job) |
b0459de4674aab56 | (.vmcx) |
89b0d939f117f75c | Adobe Acrobat 9 Pro Extended (32-bit) |
26717493b25aa6e1 | Adobe Dreamweaver CS5 (32-bit) |
e2a593822e01aed3 | Adobe Flash CS5 (32-bit) |
c765823d986857ba | Adobe Illustrator CS5 (32-bit) |
84f066768a22cc4f | Adobe Photoshop CS5 (64-bit) |
44a398496acc926d | Adobe Premiere Pro CS5 (64-bit) |

我想比较appid和f,并打印对应的item:

喜欢 appid = 89b0d939f117f75c

f = 89b0d939f117f75c | Adobe Acrobat 9 Pro Extended (32-bit)

所以我希望它根据目录列表返回89b0d939f117f75c | Adobe Acrobat 9 Pro Extended (32-bit)

有意义吗?

----代码----

import os
import sys
import urllib2
from BeautifulSoup import BeautifulSoup

path = ("C:\Users\<username>\AppData\Roaming\Microsoft\Windows\Recent\AutomaticDestinations")
for ids in os.listdir(path):
appid = "%s" % (ids).rstrip('.automaticDestinations-ms')
#print appid

f = urllib2.urlopen("http://www.forensicswiki.org/wiki/List_of_Jump_List_IDs")
s = f.read()

soup = BeautifulSoup(''.join(s))
rows = soup.findAll('tr')

for tr in rows:

    cols = tr.findAll('td', limit=2)
    for td in cols:
        text = ''.join(td.findAll(text=True))

        print text + " |",
    print "\n".strip()
f.close

【问题讨论】:

    标签: python list compare beautifulsoup


    【解决方案1】:

    从 f 制作字典并使用 appid 作为键。

    【讨论】:

      【解决方案2】:

      你想做这样的事情:

      if appid == td.split('|')[0].strip():
          print td
      

      我想。但我不清楚任何数据实际上在哪里:您的示例检索到的数据与您使用 BeautifulSoup 所做的不匹配:td 可能是错误的检查位置。

      关键是您需要将appid 与您正在搜索的文本的某些子字符串进行比较。不过,您并没有进行任何任何比较,所以我不知道您应该把它放在哪里。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-03-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-01-02
        • 1970-01-01
        相关资源
        最近更新 更多