python - Passing web data into Beautiful Soup - Empty list -


I have re-examined my code and opened the URL for comparable web data to the beautiful soup for any reason My code does not just return anything, though it is in the right form:

  gt; & Gt; Beautiful from the BS 4 import & gt; & Gt; & Gt; Urllib3 Import From Poolmanager & gt; & Gt; & Gt; ConnectBuilder = poolmanager.PoolManager () & gt; & Gt; & Gt; Content = connectBuilder.urlopen ('GET', 'http://www.crummy.com/software/BeautifulSoup/') & gt; & Gt; & Gt; Content & lt; Urllib3.response.HTTPResponse object 0x00000000032EC390 & gt; & Gt; & Gt; & Gt; Soup = beautiful soup (content)> & gt; & Gt; & Gt; Soup.title & gt; & Gt; & Gt; Soup.title.name Traceback (the most recent call final): The file "& lt; stdin>", line 1, & lt; Module & gt; AttributeError: There is no attribute 'name' in the 'NoneType' object & gt; & Gt; & Gt; Soup. P> & Gt; & Gt; Soup.get_text () '' & gt; & Gt; & Gt; A stream of data.data data is as follows ... As shown, it is clear that urlopen () returns an HTTP response that is captured by variable content. It goes, it is understandable that he can read the reaction situation, but after passing in the beautiful soup, web data is not converted into a beautiful soup object (variable soup). You can see that I have tried to read some tags and text, get_text () gives an empty list, it is weird.  

Strangely, when I use web data through content.data, data appears, but this is not useful because I can not use beautiful soup. What's my problem Thank you.

If you want to scrap the page, then you will get request Contents:

Beautiful code suit import requests from bs4 import r = requests.get ('http://www.crummy.com/software/BeautifulSoup/') soup = beautiful soup (R. content) In [59]: soup.title Out [59]: & lt; Title & gt; Beautiful Soup: We called her a tortoise because she taught us. & Lt; / Title & gt; In [60]: soup.title.name out [60]: 'title'

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -