- 今天让我们一起来看遇到字体反爬时的处理
练习网址字体反爬联系网址
这是一个JavaScript渲染的网站,所以我们要用到的工具有chrome浏览器,和selenium库先尝试一下爬取我们想要的数据看看有哪些问题:
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from scrapy import Selector
from selenium.webdriver import ChromeOptions
option = ChromeOptions()
option.add_argument('--headless')
browser = webdriver.Chrome(options=option)
browser.get('https://antispider4.scrape.center/')
WebDriverWait(browser, 10).until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, '.item')))
html = browser.page_source
selector = Selector(text=html)
items = selector.css('.item')
for item in items:
name = item.css('.name h2::text').extract_first()
categories = item.xpath('//button[contains(