我正在尝试编写一个脚本来简单地读取和打印特定帐户监视列表上的所有代码。我已经设法导航到从 HTML 打印用户名的页面,现在我想通过使用 find() 来打印他关注的所有代码来查找它们的位置,然后使用 .find_all() 来查找每个代码,但是每次我尝试使用 find() 命令导航到它返回“NoneType”的监视列表代码。
这是我的代码:
import requests
import xlwt
from xlutils.copy import copy
from xlwt import Workbook
import xlrd
import urllib.request as urllib2
from bs4 import BeautifulSoup
hisPage = ("https://stocktwits.com/GregRieben/watchlist")
page = urllib2.urlopen(hisPage)
soup = BeautifulSoup(page, "html.parser")
his_name = soup.find("span", {"class":"st_33aunZ3 st_31YdEUQ st_8u0ePN3 st_2mehCkH"})
name = his_name.text.strip()
print(name)
watchlist = soup.find("div", {"class":"st_16989tz"})
tickers = watchlist.find_all('span', {"class":"st_1QzH2P8"})
print(type(watchlist))
print(len(watchlist))
在这里,我想要突出显示的值(LSPD.CA)以及之后的所有其他值(它们都具有完全相同的 HTML 设置)
这是我的错误: