标签:soft send int font self linux中 不同 cto imp
1 pip install selenium
1 http://selenium-python.readthedocs.io/
Chrome https://sites.google.com/a/chromium.org/chromedriver/downloads Edge https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ Firefox https://github.com/mozilla/geckodriver/releases
from selenium import webdriver from scrapy.selector import Selector browser = webdriver.Chrome( executable_path="E:\Python Project\scrapyproject\_ArticleSpider\chromedriver_win32\chromedriver.exe" ) browser.get("https://www.zhihu.com/#signin") browser.find_element_by_css_selector(".view-signin input[name=‘account‘]").send_keys("18412542552") browser.find_element_by_css_selector(".view-signin input[name=‘password‘]").send_keys("as15fQAfa") browser.find_element_by_css_selector(".view-signin button.sign-button").click() # browser.quit()
from selenium import webdriver import time browser = webdriver.Chrome( executable_path="E:\Python Project\scrapyproject\_ArticleSpider\chromedriver_win32\chromedriver.exe" ) browser.get("https://weibo.com/") time.sleep(5) browser.find_element_by_css_selector("#loginname").send_keys("<username>") browser.find_element_by_css_selector(".info_list.password input[node-type=‘password‘]").send_keys("<password>") browser.find_element_by_css_selector(".info_list.login_btn a[node-type=‘submitBtn‘]").click() for i in range(3): browser.execute_script("window.scrollTo(0, document.body.scrollHeight); var lenOfPage=document.body.scrollHeight; return lenOfPage;") time.sleep(3) # browser.quit()
from selenium import webdriver chrome_opt = webdriver.ChromeOptions() prefs = {"profile.managed_default_content_settings.images":2} chrome_opt.add_experimental_option("prefs", prefs) browser = webdriver.Chrome( executable_path="E:\Python Project\scrapyproject\_ArticleSpider\chromedriver_win32\chromedriver.exe", chrome_options=chrome_opt ) browser.get("https://www.taobao.com/") # browser.quit()
1 pip install pyvirtualdisplay
sudo apt-get install xvfb
pip install xvfbwrapper
from pyvirtualdisplay import Display display = Display(visible=0, size=(800, 600)) display.start() browser = webdriver.Chrome( executable_path="E:\Python Project\scrapyproject\_ArticleSpider\chromedriver_win32\chromedriver.exe" ) browser.get(https://www.taobao.com/) # browser.quit()
1 http://phantomjs.org/download.html
from selenium import webdriver browser = webdriver.PhantomJS( executable_path="E:\Python Project\scrapyproject\_ArticleSpider\phantomjs-2.1.1-windows\bin\phantomjs.exe" ) browser.get("https://item.taobao.com/item.htm?id=558638145403&ali_refid=a3_430673_1006:1109358544:N:%E6%89%8B%E6%9C%BA%E8%8B%B9%E6%9E%9C%E6%89%8B%E6%9C%BA:5d77c360cd1e64043b2f430be7531705&ali_trackid=1_5d77c360cd1e64043b2f430be7531705&spm=a2e15.8261149.07626516002.2") print(browser.page_source) browser.quit()
import scrapy from scrapy.xlib.pydispatch import dispatcher from scrapy import signals from selenium import webdriver class JobboleSpider(scrapy.Spider): name = "jobbole" allowed_domains = ["blog.jobbole.com"] start_urls = [‘http://blog.jobbole.com/all-posts/‘] def __init__(self): self.browser = webdriver.Chrome( executable_path="E:\Python Project\scrapyproject\_ArticleSpider\chromedriver_win32\chromedriver.exe" ) super(JobboleSpider, self).__init__() dispatcher.connect(self.spider_closed, signals.spider_closed) def spider_closed(self, spider): self.browser.quit() def parse(self, response): pass
import time from scrapy.http import HtmlResponse class JSPageMiddleware(object): def process_request(self, request, spider): if spider.name == "jobbole": spider.browser.get(request.url) time.sleep(3) return HtmlResponse(url=spider.browser.current_url, body=spider.browser.page_source, encoding="utf-8", request=request)
DOWNLOADER_MIDDLEWARES = { ‘ArticleSpider.middlewares.JSPageMiddleware‘: 1, }
1 https://github.com/flisky/scrapy-phantomjs-downloader
1 https://github.com/scrapy-plugins/scrapy-splash
1 https://www.oschina.net/question/tag/selenium-grid
1 https://github.com/cobrateam/splinter
标签:soft send int font self linux中 不同 cto imp
原文地址:https://www.cnblogs.com/cq146637/p/9076281.html