했을 그것은 값싼 페이지를 건너 페이지에서 체크 쿠키 cf_clearance
페이지의 https://koinex.in/cdn-cgi/l/chk_jschl
로 보내고받을 일부 값을 생성하기 위해 자바 스크립트를 사용하는 것입니다.
코드가 쉽게 할 수 있도록 데이터
from selenium import webdriver
import time
driver = webdriver.Firefox()
driver.get('https://koinex.in/')
time.sleep(8)
tables = driver.find_elements_by_tag_name('table')
for item in tables:
print(item.text)
#print(item.get_attribute("value"))
또한 Selenium
에서 HTML
를 얻을 수 있습니다
VOLUME PRICE/ETH
5.2310 64,300.00
0.0930 64,100.00
10.7670 64,025.01
0.0840 64,000.00
0.3300 63,800.00
0.2800 63,701.00
0.4880 63,700.00
0.7060 63,511.00
0.5020 63,501.00
0.1010 63,500.01
1.4850 63,500.00
1.0000 63,254.00
0.0300 63,253.00
VOLUME PRICE/ETH
1.0000 64,379.00
0.0940 64,380.00
0.9710 64,398.00
0.0350 64,399.00
0.7170 64,400.00
0.3000 64,479.00
5.1650 64,480.35
0.0020 64,495.00
0.2000 64,496.00
9.5630 64,500.00
0.4000 64,501.01
0.0400 64,550.00
0.5220 64,600.00
DATE VOLUME PRICE/ETH
31/12/2017, 12:19:29 0.2770 64,300.00
31/12/2017, 12:19:11 0.5000 64,300.00
31/12/2017, 12:18:28 0.3440 64,025.01
31/12/2017, 12:18:28 0.0750 64,026.00
31/12/2017, 12:17:50 0.0010 64,300.00
31/12/2017, 12:17:47 0.0150 64,300.00
31/12/2017, 12:15:45 0.6720 64,385.00
31/12/2017, 12:15:45 0.2000 64,300.00
31/12/2017, 12:15:45 0.0620 64,300.00
31/12/2017, 12:15:45 0.0650 64,199.97
31/12/2017, 12:15:45 0.0010 64,190.00
31/12/2017, 12:15:45 0.0030 64,190.00
31/12/2017, 12:15:25 0.0010 64,190.00
결과를 얻기 위해 셀레늄을 사용하는 모든 요청에 다른 매개 변수와 다른 방법을 사용하여 값을 생성 할 수 있습니다 및 함께 사용 BeautifulSoup
soup = BeautifulSoup(driver.page_source)
편집 :이 코드는 Selenium
에서 쿠키를 사용합니다로드 (3210)
하지만 Selenium
는 xpath
, css selector
및 다른 방법을 그래서 대부분 BeautifulSoup
참조 문서를 사용할 필요가 없습니다 사용하여 데이터를 얻을 수 있습니다 페이지는 requests
이며 DDoS 페이지에는 아무런 문제가 없습니다.
문제는 페이지가 requests
+ BeautifulSoup
을 사용하여 가져올 수 없도록 JavaScript를 사용하여 표를 표시한다는 것입니다. 하지만 아마도 테이블에 대한 데이터를 얻기 위해 자바 스크립트에서 사용하는 URL을 찾고 requests
이 유용 할 수 있습니다.
from selenium import webdriver
import time
# --- Selenium ---
url = 'https://koinex.in/'
driver = webdriver.Firefox()
driver.get(url)
time.sleep(8)
#tables = driver.find_elements_by_tag_name('table')
#for item in tables:
# print(item.text)
# --- convert cookies/headers from Selenium to Requests ---
cookies = driver.get_cookies()
for item in cookies:
print('name:', item['name'])
print('value:', item['value'])
print('path:', item['path'])
print('domain:', item['domain'])
print('expiry:', item['expiry'])
print('secure:', item['secure'])
print('httpOnly:', item['httpOnly'])
print('----')
# convert list of dictionaries into dictionary
cookies = {c['name']: c['value'] for c in cookies}
# it has to be full `User-Agent` used in Browser/Selenium (it can't be short 'Mozilla/5.0')
headers = {'User-Agent': driver.execute_script('return navigator.userAgent')}
# --- requests + BeautifulSoup ---
import requests
from bs4 import BeautifulSoup
s = requests.Session()
s.headers.update(headers)
s.cookies.update(cookies)
r = s.get(url)
print(r.text)
soup = BeautifulSoup(r.text, 'html.parser')
tables = soup.find_all('table')
print('tables:', len(tables))
for item in tables:
print(item.get_text())
지연을 위해 JavaScript를 사용하지만 요청 + BeautifulSoup이 (가) JavaScript를 실행할 수 없습니다. 자바 스크립트를 실행하는 웹 브라우저를 제어하려면'Selenium'을 사용해야 할 수도 있습니다. 또한 쿠키를 사용하여 동일한 URL로 지연 및 전송하여 두 번째 요청인지 여부를 인식 할 수 있습니다. 어쩌면 쿠키를 가지고 있다면 지체없이로드 할 수 있습니다. 'requests.Session()'을 사용해야 할 수도 있습니다. – furas
쿠키'cf_clearance'를 삭제하면 다시 ddos 페이지가 나타납니다. 따라서이 쿠키는이 요소를 제어합니다. – furas
@furas cf_clearance를 delte하면 셀레늄을 사용하여 무지를 용서하십시오. ddos 페이지를 우회 할 수 있습니까? –