【发布时间】:2025-12-30 14:00:11
【问题描述】:
我正在编写我的第一个 python 网络抓取工具,但我无法编写代码来抓取我想要的数据。
到目前为止,这是我的代码:
import bs4 as bs
import urllib.request
source = urllib.request.urlopen ('http://finviz.com/screener.ashx?v=340&s=ta_topgainers')
soup = bs.BeautifulSoup(source, "html.parser")
#Ticker = 'quote.ashx?t'
print (Ticker)
我想从网站上提取的是这段代码:
<a href="quote.ashx?t=ETRM&ty=c&p=d&b=1">
这是整行,但我只对上面的部分感兴趣:
<a href="quote.ashx?t=ETRM&ty=c&p=d&b=1"><img src="chart.ashx?t=ETRM&ta=1&ty=c&p=d&s=l" alt="" width="700" height="340" border="0"/></a></td>
具体来说,我想提取股票代码,在本例中为 $ETRM。我想从上面的页面中提取所有上述格式的股票代码。
我尝试隔离quote.ashx?t,但它只是返回页面的整个源代码。
【问题讨论】:
-
我认为您需要通过
filter lambda or function运行结果
标签: python web-scraping