The crawl was written, but no network content was found in the result.

topic description

as the following code, I finally want to print out soup

related codes

import requests
from bs4 import BeautifulSoup
def get_webpage(url):
html_page=requests.get(url)
if html_page.status_code!=200:
    print("invalid url",html_page.status_code)
    return None
else:
    return html_page.text
site="https://tw.stock.yahoo.com/q/q?s=2377"
html=get_webpage(site)
soup=BeautifulSoup(html,"html.parser")
print(soup)

what result do you expect? What is the error message actually seen?

I expect him to release soup
but "Please press any renew." The phone told me that it didn"t show any content

.

problem description

I think there may be some blind spots, but I can"t find out

the environmental background of the problems and what methods you have tried

I am using visual studio 2017 Python application development, and have downloaded bs4

Apr.02,2021

because the function body is not indented in your code, python is strictly indented. The html_page line starts and ends with the return html_page.text line, which needs to be indented. The following is corrected:
if you fail, please post the error message. I have executed this code and there is no problem. Am I a little skeptical about the Python2 you use? this code requires Python version 3.0 or above

.
import requests
from bs4 import BeautifulSoup
def get_webpage(url):
    html_page=requests.get(url)
    if html_page.status_code!=200:
        print("invalid url",html_page.status_code)
        return None
    else:
        return html_page.text
site="https://tw.stock.yahoo.com/q/q?s=2377"
html=get_webpage(site)
soup=BeautifulSoup(html,"html.parser")
print(soup)
Menu