Skip to content

Instantly share code, notes, and snippets.

@kadnan
Created October 13, 2018 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kadnan/7045e8344002e6b4c1f1783e8db531b4 to your computer and use it in GitHub Desktop.
Save kadnan/7045e8344002e6b4c1f1783e8db531b4 to your computer and use it in GitHub Desktop.
Anti Captcha test
import requests
from bs4 import BeautifulSoup
from python_anticaptcha import NoCaptchaTaskProxylessTask, AnticaptchaClient
def get_token(s_key):
client = AnticaptchaClient(api_key)
task = NoCaptchaTaskProxylessTask(website_url=url,
website_key=s_key.strip())
job = client.createTask(task)
job.join()
return job.get_solution_response()
if __name__ == '__main__':
headers = {
'Accept': '*/*',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-US,en;q=0.9,ur;q=0.8',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Pragma': 'no-cache',
'Referer': 'https://losangeles.craigslist.org/lac/sub/d/january-july-private-bedroom/6721286531.html',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36',
'X-Requested-With': 'XMLHttpRequest'
}
api_key = '<api_key>'
site_key = '6Lc-0DYUAAAAAOPM3RGobCfKjIE5STmzvZfHbbNx'
url = 'https://losangeles.craigslist.org/reply/lax/sub/6721286531'
session = requests.session()
r = session.get(url, headers=headers)
print(r.status_code)
if r.status_code == 200:
html = r.text
soup = BeautifulSoup(html, 'lxml')
n_section = soup.find('input', {'name': 'n'})
site_key_section = soup.find('input', {'name': 'site_key'})
print('Site = {}'.format(site_key_section['value']))
n_value = n_section['value']
token = get_token(site_key_section['value'])
print(token)
print('Calling POST...')
r = session.post(url, headers=headers, data={'g-recaptcha-response': token,
'n': n_value})
print(r.status_code)
if r.status_code == 200:
print(r.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment