This is probably a really easy fix but I don’t know how to do it. I’m using Python.
JavaScript
x
14
14
1
from bs4 import BeautifulSoup as beauty
2
import cloudscraper
3
4
5
scraper = cloudscraper.create_scraper(delay=10, browser='chrome') #
6
url = ""
7
8
info = scraper.get(url).text
9
soup = beauty(info, "html.parser")
10
description = soup.find_all('meta', property_ = 'og:title')
11
12
for og:title in description:
13
print(og:title.text)
14
I just want to search for og:title in description but the : in og:title keeps giving me a syntax error. I tried quotation marks but that didn’t work. I had the same problem with a – sign in another thing I was searching for. How do I make python treat them as just text? Sorry for bad question this is my first day ever coding
Advertisement
Answer
JavaScript131for og:title in description:
2print(og:title.text)
3
That’s not valid python code.
Identifiers should contain alphanumeric
and _
underscore characters.
Avoid putting :
colon in an identifier.
Spell it this way and you should be fine:
JavaScript
1
3
1
for og_title in description:
2
print(og_title.text)
3