AttributeError:'NoneType'对象在bs4中没有属性'find'

时间:2020-08-10 10:01:52

标签: html python-3.x web-scraping beautifulsoup

我当时正在从筛查器网站上抓取股票行情记录。我尝试了以下代码。

import datetime as dt
import requests
import bs4
import lxml
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np 
import math
from alpha_vantage.timeseries import TimeSeries
from alpha_vantage.techindicators import TechIndicators

url=r'https://www.marketwatch.com/tools/stockresearch/screener/results.asp?submit=Screen&Symbol=true&Symbol=false&ChangePct=true&ChangePct=false&FiftyTwoWeekLow=false&CompanyName=true&CompanyName=false&Volume=true&Volume=false&PERatio=false&Price=true&Price=false&LastTradeTime=false&MarketCap=false&Change=true&Change=false&FiftyTwoWeekHigh=false&MoreInfo=true&MoreInfo=false&SortyBy=Symbol&SortDirection=Descending&ResultsPerPage=OneHundred&TradesShareEnable=false&TradesShareMin=&TradesShareMax=&PriceDirEnable=true&PriceDir=Up&PriceDirPct=100&LastYearEnable=false&LastYearAboveHigh=&TradeVolEnable=false&TradeVolMin=&TradeVolMax=&BlockEnable=false&BlockAmt=&BlockTime=&PERatioEnable=false&PERatioMin=&PERatioMax=&MktCapEnable=false&MktCapMin=&MktCapMax=&MovAvgEnable=false&MovAvgType=Outperform&MovAvgTime=FiftyDay&MktIdxEnable=false&MktIdxType=Outperform&MktIdxPct=&MktIdxExchange=&Exchange=All&IndustryEnable=false&Industry='

res=requests.get(url)
soup=bs4.BeautifulSoup(res.text, 'lxml')
tick=soup.find('td', {'class' :'aleft'}).find('a').text
print(tick)

但是发生了以上错误。请帮帮我!

1 个答案:

答案 0 :(得分:1)

我运行了您的代码,它运行良好。我得到了提到要刮擦的标签的文本。请看下面的屏幕截图。请再试一次,让我知道您是否遇到相同的问题。

enter image description here