0

I'm working on a web scraping project

When i run my code :

url = myurl

session = requests.session()
response = session.get(url)
print(response.content)

The response.content looks like this:

<html><head><meta charset="utf-8"><script>function i700(){}i700.F20=function (){return typeof i700.O20.p60==='function'?i700.O20.p60.apply(i700.O20,arguments):i700.O20.p60;};i700.X70=function (){return typeof i700.v70.p60.............................

Inspecting the source webpage using Firefox Dev Tools, I found the data I need.

BlackMath
  • 1,708
  • 1
  • 11
  • 14

2 Answers2

0

The response that you showed does not appear to be gziped; response.content will return the response as a binary byte-string, which is likely not what you want.

In order to get the response in plain-text, you will want to use response.text. From there, you should be able to search the string for the element that you want using string.find().

Source: requests documentation.

  • Thanks Drew, i tried your solution, but `response.text` produces the same output of `response.content` . This source seems not to be a binary byte-string, it looks like a compressed javascript functions. When i visit the site with a standard browser, "source html" looks ok. When i try to get it from requests library or Selenium, the source looks weird. – BlackMath May 21 '20 at 14:22
0

After some reserches, i found the solution. I noticed that my target website can detect Selenium as bot, even though there's no automation applied.

So, to access this kind of web page without getting detected, i found a solution using the ChromeOptions() class to add some arguments to:

options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"]) 
options.add_experimental_option('useAutomationExtension', False) 

Source: Selenium webdriver: Modifying navigator.webdriver flag to prevent selenium detection

BlackMath
  • 1,708
  • 1
  • 11
  • 14