作者busystudent (busystudent)
看板Python
标题[问题] 网页分析之print问题
时间Sat Apr 2 00:04:24 2016
晚安,很高兴在这里问问题,提升程式功力
2. 请看我程式码
import requests
import re
from BeautifulSoup import BeautifulSoup
import HTMLParser
links = ['
https://goo.gl/dBtn3H']
上述的程式码大概说明是我爬虫了一个叫做
https://goo.gl/dBtn3H的网页,我接下来为会撷取我想要的一段网页内容,如下所示
#抓取使用者所收藏的标签(未处理)
for link in links:
res = requests.get(link)
soup = BeautifulSoup(res.text.encode("utf-8"))
shop_table = soup.findAll('div',{'class':'userListTags'})
shop_table[0].findAll('a',{'href':True})
for each in shop_table:#印出所
print(each)
print each#出问题了 没有印出全部资料
上述有两次撷取,第一次为div.....,第二次为 shop_table[0].findAll('a',{'href':True})
我想请问当我用for回圈( for each in shop_table:)时可以印出所有我想要的资料,但是我当我外在for回圈外面再写一个print each时,却只会印印少少几行呢?
--
Sent from my Windows
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 123.110.158.25
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1459526667.A.AA0.html
1F:→ ck574b027: 第二个 each 只会是 shop_table 最後一个 element 吧 04/02 00:07
2F:→ busystudent: 哇 等等 你可以说清楚一点吗!! 04/02 00:08
3F:→ busystudent: 还有我该如何处理这个问题呢? 我希望把完整版的print 04/02 00:10
4F:→ busystudent: 存进我本机,可是一直存到不完整版那个 04/02 00:10
5F:→ checkIO: For都跑完了 当然你print就是最後一个each值啊 04/02 09:38
6F:→ checkIO: 因为你存的地方犯错了吧 for回圈不熟? 去写个九九乘法你 04/02 09:41
7F:→ checkIO: 就知道问题在哪了 04/02 09:41
8F:→ octantis: 还有shop_table[0].findAll('a',{'href':True})无意义 04/02 12:22
9F:→ octantis: 你没用任何变数去reference它 04/02 12:23
10F:→ MOONY135: 回答完才知道楼上已经点出他的盲点在哪了... 04/02 14:28