作者octantis (@.@)
看板Python
标题Re: [问题] 关於程式输出时如何呼叫第二支程式的问题
时间Fri Apr 22 05:15:39 2016
※ 引述《busystudent (busystudent)》之铭言:
: a主程式码
: http://dpaste.com/2S5SC2B
你主程式码下面有问题
links = ['
http://www.diigo.com/user/tony_swann/' + a ]放到外面去
否则只有一个然後包成list再用for进去list里读出来有何意义?
改成:
links = ['
http://www.diigo.com/user/tony_swann/' + x for x in tag_list]
for link in links:
res = requests.get(link)
soup = BeautifulSoup(res.text.encode("utf-8"), 'html.parser')
fol_table = soup.findAll('div', {'class': 'Titleinner'})
a_links = [tag['href'] for link in fol_table
for tag in link.findAll('a', {'href': True})]
#将一个tag的所有结果放进同一个list,然後将list丢给b主程式码
可简化成a_links = [a['href'] for a in soup.select('div.Titleinner a')]
将fol_table与a_link合并
结构:
links里装所有的标签
a_link为一个标签里的所有分析到的网址
然後把a_link丢进b主程式码
: b主程式码
: http://dpaste.com/1A5ZHM8
不知道是不是你要的答案,你的问题我要想很久才猜得到你"可能"想表达的意思...
列出你想得到的答案型式,不然光猜就要猜好久
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 1.164.133.245
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1461273344.A.39E.html
※ 编辑: octantis (1.164.133.245), 04/22/2016 06:18:04
1F:→ MOONY135: 看描述就觉得好乱喔... 04/22 10:24
2F:推 busystudent: 你好 谢谢你的回文,之前的叙述不好,不好意思 04/22 12:01
3F:→ busystudent: 我把文章叙述修改了 04/22 12:02
4F:推 busystudent: 你好 有一行我看不懂,想请你解释 04/22 16:39
5F:推 busystudent: a_links = [tag['href'] for link in fol_table 04/22 16:41
6F:→ busystudent: for tag in link.findAll('a', {'hr 04/22 16:41
7F:→ busystudent: ef': True})] 04/22 16:41
8F:→ busystudent: 这一行是什麽意思? 04/22 16:41
9F:→ busystudent: 我第一看到撰写两种for在一行的式子 04/22 16:42
10F:→ octantis: 就是相当於for回圈里再一个for回圈 04/22 17:03
11F:→ octantis: 不然就是用下面写的简化版 看起来比较乾净简单 04/22 17:04
12F:→ octantis: 那行等於 04/22 17:05
13F:→ octantis: for link in fol_table: 04/22 17:06
14F:→ octantis: for tag in link.findAll('a', {'href': True}): 04/22 17:07
15F:→ octantis: a_links.append(tag['href']) 04/22 17:08
16F:推 busystudent: 谢谢你的说明! 04/22 17:09
17F:→ busystudent: 还有简化版那行一否有误,它报错'NoneType' 04/22 17:10
19F:→ octantis: 啊!你是用bs3而非bs4,难怪会出错,bs3可能没法这样用 04/22 20:14