Python Forum
my soup.find_all is not finding anything: it runs into a empty-list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
my soup.find_all is not finding anything: it runs into a empty-list
#1
hi there

i use python to do some beginner-webscraping.
i am using a simple basic-script that captures stock price data: the nice thing it should do this in real time, and then it should updating it self.



At the moment i have found out some issues: my soup is finding a empty list -


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import bs4
 
import requests
 
from bs4 import BeautifulSoup
 
 
 
def parsePrice():
 
 
`soup=bs4.BeautifulSoup(r.text,"xml")`
 
`price=soup.find_all('div',{'class':'My(6px) Post(r) smartphone_Mt(6px)'})[0].find('span').text`
 
`return price`
 
 
while True:
 
`print('the current price_ '+str (parsePrice()))`
1
2
3
4
5
6
7
8
9
10
11
Traceback (most recent call last):
 
File "C:\Users\Kasper\Documents\_f_s_j\_mk_\_dev_\bs\yahoo_finance.py", line 14, in <module>
 
print('the current price_ '+str (parsePrice()))
 
File "C:\Users\Kasper\Documents\_f_s_j\_mk_\_dev_\bs\yahoo_finance.py", line 10, in parsePrice
 
price=soup.find_all('div',{'class':'My(6px) Post(r) smartphone_Mt(6px)'})[0].find('span').text
 
IndexError: list index out of range
after musing some time i saw: well my soup.find_all is not finding anything: This causes the [0] since it is quite out of range because the find_all returns an empty list.

Wink
Wordpress - super toolkits a. http://wpgear.org/ :: und b. https://github.com/miziomon/awesome-wordpress :: Awesome WordPress: A curated list of amazingly awesome WordPress resources and awesome python things https://github.com/vinta/awesome-python
Reply
#2
It's a mess with no indentation and strange quotation mark Wink
No will code not work anyway,look at Web-scraping part-2 under JavaScript why do i not get all content.
Here a another post take some data from an other stock site.

Also there are API or PyPi modules for many of these stocks sites 5 free stock market APIs for Python in 2020

apollo Wrote:i use python to do some beginner-webscraping
This is not beginner web-scraping,as you have choose one of the hardest site to scrape Doh
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Soup('A') new_coder_231013 5 7,622 Oct-13-2024, 06:19 AM
Last Post: Pedroski55
  Beautiful Soup find_all() kirito85 2 4,171 Jun-14-2019, 02:17 AM
Last Post: kirito85
  xpath returns an empty list haye 5 11,292 Nov-24-2017, 09:53 AM
Last Post: heiner55
  Confusion between find() and find_all() Prince_Bhatia 3 8,420 Sep-18-2017, 09:41 AM
Last Post: Prince_Bhatia

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020