Home>

I'm thinking of scraping with python.
Can you tell me how I can get an error during implementation?

Error message

Error message
print (tag)
^
IndentationError: expected an indented block

Applicable source code

`` `Enter the language name here
Source code
import requests
response = requests.get ("https://review-of-my-life.blogspot.com/")
print (response.text)
html_doc = requests.get ("https://review-of-my-life.blogspot.com") .text
soup = BeautifulSoup (html_doc, 'html.parser') # Initialize BeautifulSoup
print (soup.prettify ())

TODO1 Please extract all a tags on this page. (HTML content)

real_page_tags = soup.find_all ("a")
for tag in real_page_tags:
print (tag)

TODO2 Please extract all a tags on this page. (HTML content)

for tag in real_page_tags:
print (tag.string)

TODO3 Please extract all a tags on this page. (HTML content)

for tag in real_page_tags:
print (tag.get ("href"))

Please describe what you tried for the problem here.
Insert print ("hello world") and the print function itself is
I confirmed that it was not strange.

Supplemental information (FW/tool version etc.)

The source code was read and copied.
https://dividable.net/python/python-scraping/
Please include more detailed information here.
The error itself is in the 11th line and is in the error message.
Requests/BeautifulSoup is already installed.

  • Answer # 1

    Because python is a block indent, the next line of:must be a 4-character space.

    for tag in real_page_tags:
        print (tag)

    If there are no other errors, this probably works.