Skip to content
Advertisement

Python scraping website shows unknown url type: view-source

I am trying to do scraping in Python.

Then, I want to scrape a stock-info website. But I failed, I don’t know why.

import urllib

# wallstreetcn info page
url_src = 'view-source:https://wallstreetcn.com/live/global?from=navbar'

url_content = urllib.request.urlopen(url_src)

It gives the error below:

URLError: urlopen error unknown url type: view-source

But when I used Chrome I can view the source code by right-click.

Advertisement

Answer

Try removing view-source: from your url_src, in essence:

url_src = 'https://wallstreetcn.com/live/global?from=navbar'

I think view-source: is Chrome specific (so Chrome knows to show you source rather than the webpage).

Advertisement