小编keg*_*ewe的帖子

从标签beautifulsoup python中提取类名

我有以下HTML代码:

    <td class="image">
      <a href="/target/tt0111161/" title="Target Text 1">
       <img alt="target img" height="74" src="img src url" title="image title" width="54"/>
      </a>
     </td>
     <td class="title">
      <span class="wlb_wrapper" data-caller-name="search" data-size="small" data-tconst="tt0111161">
      </span>
      <a href="/target/tt0111161/">
       Other Text
      </a>
      <span class="year_type">
       (2013)
      </span>
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用漂亮的汤将某些元素解析为制表符分隔的文件。我得到了很大的帮助,并且有:

for td in soup.select('td.title'):
 span = td.select('span.wlb_wrapper')
 if span:
     print span[0].get('data-tconst') # To get `tt0082971`
Run Code Online (Sandbox Code Playgroud)

现在,我想获取“目标文本1”。

我已经尝试过类似上述内容的操作,例如:

for td in soup.select('td.image'): #trying to select the <td class="image"> tag
img = td.select('a.title') #from inside td I now try to look inside the a …
Run Code Online (Sandbox Code Playgroud)

html python parsing beautifulsoup

6
推荐指数
1
解决办法
2万
查看次数

比较列pandas python

我有一个包含5列和多行的csv文件,格式如下:

BAL 27  DEN 49  2013-09-05T20:30:00   
Run Code Online (Sandbox Code Playgroud)

我想比较2个分数并将获胜者的名字作为第6列返回

我试过这个:

from pandas import read_csv
Games = open("games.csv","rb")
df = read_csv(Games, header=None)
#print df
#print df[0]

if df[3] > df[1]:
    print df[2]
else:
    print df[0]
Run Code Online (Sandbox Code Playgroud)

我得到了一个 ValueError: The truth value of a Series is ambiguous

我有什么想法可以实现我的目标?

python csv numpy multiple-columns pandas

5
推荐指数
2
解决办法
4673
查看次数

标签 统计

python ×2

beautifulsoup ×1

csv ×1

html ×1

multiple-columns ×1

numpy ×1

pandas ×1

parsing ×1