用于循环的web抓取卡在列表的第一项上-python
我试着循环浏览一个名字列表,看起来应该很简单,但不起作用。只收到名单上的第一个名字而已!为什么不换下一个名字 这是我的密码:用于循环的web抓取卡在列表的第一项上-python,python,for-loop,web-scraping,beautifulsoup,Python,For Loop,Web Scraping,Beautifulsoup,我试着循环浏览一个名字列表,看起来应该很简单,但不起作用。只收到名单上的第一个名字而已!为什么不换下一个名字 这是我的密码: import pandas as pd import requests from bs4 import BeautifulSoup page = requests.get('http://www.aus.edu/info/200170/college_of_architecture_art_and_design/269/department_of_architectur
import pandas as pd
import requests
from bs4 import BeautifulSoup
page = requests.get('http://www.aus.edu/info/200170/college_of_architecture_art_and_design/269/department_of_architecture/4')
soup = BeautifulSoup (page.content, "html.parser")
content = soup.find(class_="supContact")
content_items = content.find_all(class_="contactToggle selected")
names = content_items[0]
s_name = []
for item in name:
s_name.append(content.find(class_="contactToggle selected").text)
if not names:
continue
print(s_name)
#print(names.prettify())
您确定没有在for循环中将
名称
与名称
混淆,并且如果/继续
?根据您的筛选器class=“contactToggle selected”
它将返回一个名称,即内容项
仅包含一项。所以现在还不清楚你到底想要实现什么,投票结束这个问题不用担心,我已经解决了这个问题。谢谢