打印输出双重结果
Print outputs double results
脚本正在打印双重结果,我无法真正确定问题所在。
# -*- 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
您搜索的内容在页面源代码中出现了两次。
查看来源:
在浏览器中粘贴view-source:http://www.tabula.ge/en
或右击网页选择"view page source"
出现了两次:
<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>
脚本正在打印双重结果,我无法真正确定问题所在。
# -*- 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
您搜索的内容在页面源代码中出现了两次。
查看来源:
在浏览器中粘贴
view-source:http://www.tabula.ge/en
或右击网页选择"view page source"
出现了两次:
<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>