0

I'd like to download the css of a page and achieve the same appearance as in the browser. The problem is that the scraped result looks different.

For example, I want to download the landing page of google.

That's the code I have used:

import requests
from requests_html import HTMLSession

session = HTMLSession()

r = session.get('https://www.google.com')

r.html.render()

file = open("start.html", "w")
file.write(r.text)
file.close()
jlewkovich
  • 2,725
  • 2
  • 35
  • 49
  • Does this answer your question? [How can I download full webpage by a Python program?](https://stackoverflow.com/questions/31205497/how-can-i-download-full-webpage-by-a-python-program) – glotchimo Feb 01 '20 at 23:03

1 Answers1

0

The css is usually in a tag.

Try to parse the page in bs4

from bs4 import BeautifulSoup as BS
from requests_html import HTMLSession

session = HTMLSession()

r = session.get('https://www.google.com')

r.html.render()

soup=BS(r.text)

css = [link.get("href") for link in soup.findAll("link") if "stylesheet" in link.get("rel")]

Now css should be a list of links to the css used

Bendik Knapstad
  • 1,409
  • 1
  • 9
  • 18