scrapingbee python
v2.0.1:
Scrapingbee는 헤드리스 브라우저를 처리하고 프록시를 회전시키는 웹 스크래핑 API입니다. Python SDK를 사용하면 ScrapingBee의 API와 더 쉽게 상호 작용할 수 있습니다.
PIP와 함께 ScrapingBee Python SDK를 설치할 수 있습니다.
pip install scrapingbee
Scrapingbee Python SDK는 요청 라이브러리 주변의 래퍼입니다. Scrapingbee는 요청 및 게시 요청을 지원합니다.
ScrapingBee에 가입하여 API 키를 얻고 무료 크레딧을 시작하십시오.
>> > from scrapingbee import ScrapingBeeClient
>> > client = ScrapingBeeClient ( api_key = 'REPLACE-WITH-YOUR-API-KEY' )
>> > response = client . get (
'https://www.scrapingbee.com/blog/' ,
params = {
# Block ads on the page you want to scrape
'block_ads' : False ,
# Block images and CSS on the page you want to scrape
'block_resources' : True ,
# Premium proxy geolocation
'country_code' : '' ,
# Control the device the request will be sent from
'device' : 'desktop' ,
# Use some data extraction rules
'extract_rules' : { 'title' : 'h1' },
# Wrap response in JSON
'json_response' : False ,
# Interact with the webpage you want to scrape
'js_scenario' : {
"instructions" : [
{ "wait_for" : "#slow_button" },
{ "click" : "#slow_button" },
{ "scroll_x" : 1000 },
{ "wait" : 1000 },
{ "scroll_x" : 1000 },
{ "wait" : 1000 },
]
},
# Use premium proxies to bypass difficult to scrape websites (10-25 credits/request)
'premium_proxy' : False ,
# Execute JavaScript code with a Headless Browser (5 credits/request)
'render_js' : True ,
# Return the original HTML before the JavaScript rendering
'return_page_source' : False ,
# Return page screenshot as a png image
'screenshot' : False ,
# Take a full page screenshot without the window limitation
'screenshot_full_page' : False ,
# Transparently return the same HTTP code of the page requested.
'transparent_status_code' : False ,
# Wait, in miliseconds, before returning the response
'wait' : 0 ,
# Wait for CSS selector before returning the response, ex ".title"
'wait_for' : '' ,
# Set the browser window width in pixel
'window_width' : 1920 ,
# Set the browser window height in pixel
'window_height' : 1080
},
headers = {
# Forward custom headers to the target website
"key" : "value"
},
cookies = {
# Forward custom cookies to the target website
"name" : "value"
}
)
>> > response . text
'<!DOCTYPE html><html lang="en"><head>...'
ScrapingBee는 다양한 매개 변수를 사용하여 JavaScript를 렌더링하고 사용자 정의 JavaScript 스크립트를 실행하며 특정 지리적 위치에서 프리미엄 프록시를 사용합니다.
ScrapingBee의 문서에서 지원되는 모든 매개 변수를 찾을 수 있습니다.
일반적으로 요청 라이브러리와 함께 할 수있는 맞춤형 쿠키 및 헤더를 보낼 수 있습니다.
여기에서 Scrapingbee 블로그에서 스크랩 샷을 검색하고 저장하는 방법에 대해 약간의 예를 들어 모바일 해상도로 저장하십시오.
>> > from scrapingbee import ScrapingBeeClient
>> > client = ScrapingBeeClient ( api_key = 'REPLACE-WITH-YOUR-API-KEY' )
>> > response = client . get (
'https://www.scrapingbee.com/blog/' ,
params = {
# Take a screenshot
'screenshot' : True ,
# Specify that we need the full height
'screenshot_full_page' : True ,
# Specify a mobile width in pixel
'window_width' : 375
}
)
>> > if response . ok :
with open ( "./scrapingbee_mobile.png" , "wb" ) as f :
f . write ( response . content )
스크랩은 가장 인기있는 파이썬 웹 스크래핑 프레임 워크입니다. ScrapingBee의 API를 스크랩 미들웨어와 쉽게 통합 할 수 있습니다.
클라이언트에는 5xx 응답을위한 재 시도 메커니즘이 포함되어 있습니다.
>> > from scrapingbee import ScrapingBeeClient
>> > client = ScrapingBeeClient ( api_key = 'REPLACE-WITH-YOUR-API-KEY' )
>> > response = client . get (
'https://www.scrapingbee.com/blog/' ,
params = {
'render_js' : True ,
},
retries = 5
)