小编use*_*378的帖子

For Loop | 蟒蛇

我第一次使用Python进行网页抓取,在做代码时,我陷入了for循环.

我们可以看到,b和a都返回一个列表.我使用for循环迭代b和a的列表值,并按顺序打印:

期望的输出

first value of b, first value of a, second value of b, second value of a....
Run Code Online (Sandbox Code Playgroud)

这是代码:

b = soup.find("module", {"type":"Featured Link List Advanced"}).find_all("span")

a = soup.find("module", {"type":"Featured Link List Advanced"}).find("ul").find_all("a")\

for i in b:
   print (i.string)
   for j in a:
      print (j.get("href"))
      break
Run Code Online (Sandbox Code Playgroud)

但我得到的输出是:

First value of b, First value of a, second value of b, first value of a, third value of, first value of a, 
Run Code Online (Sandbox Code Playgroud)

有人可以帮助我获得所需的输出吗?我知道我错过了什么.

python

3
推荐指数
1
解决办法
114
查看次数

标签 统计

python ×1