Skip to content

Instantly share code, notes, and snippets.

@kadnan
Created Oct 13, 2018
Embed
What would you like to do?
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