用 Python 抓取,提取数字
Scraping with Python, extracting number
这是我的第一个 Python 代码,如有任何帮助,我们将不胜感激。
我已经能够抓取网页,得到一组文本作为输出。我无法从那里进一步移动。
代码:
page = requests.get("https://www.traderscockpit.com/?pageView=live-nse-advance-decline-ratio-chart")
soup = BeautifulSoup(page.content, 'html.parser')
Adv = soup.find(class_="advDec")
Adv
结果
<p class="advDec"><a href="/?pageView=nse-top-gainers" title="Click to view list of Advanced stocks">Advanced:</a> 736</p>
我现在不知道如何提取数字 736,它位于右侧的 a 和 p 之间。
你能帮忙吗?
page = requests.get("https://www.traderscockpit.com/?pageView=live-nse-advance-decline-ratio-chart")
soup = BeautifulSoup(page.content, 'html.parser')
Adv = soup.find('p', class_="advDec")
Adv.text
这是我的第一个 Python 代码,如有任何帮助,我们将不胜感激。
我已经能够抓取网页,得到一组文本作为输出。我无法从那里进一步移动。
代码:
page = requests.get("https://www.traderscockpit.com/?pageView=live-nse-advance-decline-ratio-chart")
soup = BeautifulSoup(page.content, 'html.parser')
Adv = soup.find(class_="advDec")
Adv
结果
<p class="advDec"><a href="/?pageView=nse-top-gainers" title="Click to view list of Advanced stocks">Advanced:</a> 736</p>
我现在不知道如何提取数字 736,它位于右侧的 a 和 p 之间。 你能帮忙吗?
page = requests.get("https://www.traderscockpit.com/?pageView=live-nse-advance-decline-ratio-chart")
soup = BeautifulSoup(page.content, 'html.parser')
Adv = soup.find('p', class_="advDec")
Adv.text