My code for crawling a Quora question is the following:
import requests
from bs4 import BeautifulSoup
import pandas as pd
URL = "https://www.quora.com/What-is-the-best-workout-1"
page = requests.get(URL)
soup = BeautifulSoup(page.text, "html.parser")
print(soup.find_all("span", {"class": "q-box qu-userSelect--text"}))
The outcome is an empty list.
The problem is that page.text doesn't contain the same source code like the one I get when I inspect element on Quora.
Instead it contains the following text which doesn't include any <span> elements
Here is the code I get when using Inspect Element
Try:
prints:
and so on...
I not sure that it is
q-box qu-userSelect--textyou actually want. But it was what you asked for so..Note selenium: You need selenium and geckodriver and in this code geckodriver is set to be imported from
c:/program/geckodriver.exe