写一个基本的爬虫:

  1. from selenium import webdriver
  2. def main(url):
  3. driver = webdriver.Chrome()
  4. driver.get(url)
  5. html = driver.page_source
  6. driver.close()
  7. soup = BeautifulSoup(html)
  8. title = soup.title.string
  9. description = soup.find(attrs={"name": "description"})['content']
  10. # keywords = soup.find(attrs={"name": "keywords"})['content']
  11. print('title:', title)
  12. print('description:', description)
  13. # print('keywords:', keywords)

安装 chromedriver

On Ubuntu:

  1. sudo apt install chromium-chromedriver

On Debian:

  1. sudo apt install chromium-driver

On macOS install https://brew.sh/ then do

  1. brew cask install chromedriver