【发布时间】:2019-12-31 12:26:57
【问题描述】:
我阅读了很多关于该主题的帖子,也尝试了本文的一些建议,但我仍然被阻止。
https://www.scraperapi.com/blog/5-tips-for-web-scraping
-
IP 轮换:完成我使用 VPN 并经常更改 IP(但显然不是在脚本期间)
-
设置一个真正的用户代理:实现了假用户代理,没有运气
-
设置其他请求标头:尝试使用 SeleniumWire 但如何同时使用它而不是 2.?
-
在您的请求之间设置随机间隔:完成但无论如何目前我什至无法访问起始主页!!!
-
设置referer:同3。
-
使用无头浏览器:没有线索
-
避免蜜罐陷阱:同4。
-
- 10:不相关
我要抓取的网站:https://www.winamax.fr/paris-sportifs/
没有 Selenium:它可以顺利转到包含一些游戏及其赔率的页面,我可以从这里导航
使用 Selenium:页面显示“Winamax est actuellement en maintenance”消息,没有游戏,也没有赔率
尝试执行这段代码,你可能很快就会被阻塞:
from selenium import webdriver
import time
from time import sleep
import json
driver = webdriver.Chrome(executable_path="chromedriver")
driver.get("https://www.winamax.fr/paris-sportifs/") #I'm even blocked here now !!!
toto = driver.page_source.splitlines()
titi = {}
matchez = []
matchez_detail = []
resultat_1 = {}
resultat_2 = {}
taratata = 1
comptine = 1
for tut in toto:
if tut[0:53] == "<script type=\"text/javascript\">var PRELOADED_STATE = ": titi = json.loads(tut[53:tut.find(";var BETTING_CONFIGURATION = ")])
for p_id in titi.items():
if p_id[0] == "sports":
for fufu in p_id:
if isinstance(fufu, dict):
for tyty in fufu.items():
resultat_1[tyty[0]] = tyty[1]["categories"]
for p_id in titi.items():
if p_id[0] == "categories":
for fufu in p_id:
if isinstance(fufu, dict):
for tyty in fufu.items():
resultat_2[tyty[0]] = tyty[1]["tournaments"]
for p_id in resultat_1.items():
for tgtg in p_id[1]:
for p_id2 in resultat_2.items():
if str(tgtg) == p_id2[0]:
for p_id3 in p_id2[1]:
matchez.append("https://www.winamax.fr/paris-sportifs/sports/"+str(p_id[0])+"/"+str(tgtg)+"/"+str(p_id3))
for alisson in matchez:
print("compet " + str(taratata) + "/" + str(len(matchez)) + " : " + alisson)
taratata = taratata + 1
driver.get(alisson)
sleep(1)
elements = driver.find_elements_by_xpath("//*[@id='app-inner']/div/div[1]/span/div/div[2]/div/section/div/div/div[1]/div/div/div/div/a")
for elm in elements:
matchez_detail.append(elm.get_attribute("href"))
for mat in matchez_detail:
print("match " + str(comptine) + "/" + str(len(matchez_detail)) + " : " + mat)
comptine = comptine + 1
driver.get(mat)
sleep(1)
elements = driver.find_elements_by_xpath("//*[@id='app-inner']//button/div/span")
for elm in elements:
elm.click()
sleep(1) # and after my specific code to scrape what I want
【问题讨论】:
标签: python selenium selenium-chromedriver