首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >打印输出双倍结果

打印输出双倍结果
EN

Stack Overflow用户
提问于 2015-06-16 19:46:05
回答 1查看 105关注 0票数 0

这个脚本正在打印双重结果,我无法确定问题的答案。

代码语言:javascript
复制
# -*- coding: utf-8 -*-
import requests
from bs4 import BeautifulSoup as bs

word = ("mission")

with requests.Session() as s:
    r = s.get('http://www.tabula.ge/en')
    soup = bs(r.text)
    div = soup.find("div", {"class": "sets"})           


    for i in div.find_all('li'):
        for text in i.find_all('a'):
            if word in text.encode('utf-8').strip():
                print text.get_text()

运行脚本后,我将在打印输出中获得两次结果:

Kandelaki: Georgian UN mission yet to call security council meeting

Kandelaki: Georgian UN mission yet to call security council meeting

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-16 19:51:57

搜索的内容在页面源中发生两次。

若要查看消息来源:

  • 粘贴在浏览器view-source:http://www.tabula.ge/en
  • 或右键单击网页并选择“查看页源”。

这种情况有两种情况:

代码语言:javascript
复制
<a href="/en/story/90354-kandelaki-georgian-un-mission-yet-to-call-security-council-meeting" data-topic="UN Security Council Meeting" data-video="false" data-date="December 1 2014, 03:13PM" data-comment-count="0" data-thumbnail="http://www.tabula.ge/files/styles/tab_thumb_featured/public/photos/2014/12/giorgi-kandelaki.jpg?itok=uKdw1i9k" data-nid="90354">
                         Kandelaki: Georgian UN mission yet to call security council meeting                    </a>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30876793

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档