【发布时间】:2021-03-02 18:13:57
【问题描述】:
我正在尝试使用 2captcha 绕过验证码,同时在 wayfair.com 上抓取产品类别 我使用的代码是;
def parse(self,response):
l=[]
resp3 = Selector(text=self.driver.page_source)
self.driver.get("https://www.wayfair.com/filters/storage-organization/sb6/closet-systems-c1833181-a72947~471760-a72947~471761-a72947~471762-a72947~471763-a72947~493985-a72947~494649.html")
our_condition = resp3.xpath('//span[@class="BrowseHeaderWithSort-roadsign"]/text()').get()
# if resp3.xpath('//div[@class="g-recaptcha"]').get() != None:
if our_condition in ['Closet Systems']:
print('/////30 sec/////')
time.sleep(2)
else:
print('captcha detected')
time.sleep(60)
while True:
api_key = '4f4796f8w4782b0d45621897818c7d58e'
site_key = '6LfaBQEaAAAAAG8Z0xFqTFgOykhR3HmCEPlImW2T' # grab from site
client = AnticaptchaClient(api_key)
task = NoCaptchaTaskProxylessTask(self.driver.current_url, site_key)
while True:
job = client.createTask(task)
print("Waiting for solution")
job.join()
response = job.get_solution_response()
print("captcha solution", response)
if len(response) > 0:
break
print('injecting the token on html')
self.driver.execute_script(f'document.getElementById("g-recaptcha-response").innerHTML="{response}";')
print('injecting the token on html. Success!')
time.sleep(3)
self.driver.find_element_by_xpath('//button[@class="submit"]').click()
time.sleep(3)
resp = Selector(text=self.driver.page_source)
if resp.xpath('//div[@class="g-recaptcha"]/@data-site-key').get() == None:
break
我在 VS 代码中遇到的错误在这里
raise AnticaptchaException( python_anticaptcha.exceptions.AnticaptchaException: [ERROR_KEY_DOES_NOT_EXIST:1]Account authorization key not found in the system 2021-03-02 19:10:09 [scrapy.extensions.logstats]
我正在努力了解实际问题是什么,如何摆脱它,并让 2captcha 在抓取时解决验证码。谢谢
【问题讨论】:
-
嗯,实际的问题是 wayfair.com 不希望你抓取他们的网站。他们有代码来防御这种代码。
api_key和site_key可能是动态的,所以你不能只是重复使用它们。 -
是说,我应该离开爬wayfair.com,还是有什么出路,仍然可以帮助我爬取数据
-
我确定这是可能的,但您可能需要他们的帮助来找出关键机制。
标签: python selenium web-scraping recaptcha