python 爬虫
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 爬虫相关的知识,希望对你有一定的参考价值。
网页访问常用到库:
requests(网页请求)
BeautifulSoup(从网页抓取数据)
selenium(模拟浏览器行为)
PhantomJS(虚拟浏览器)
import requests from bs4 import BeautifulSoup from selenium import webdriver res = requests.get(url) res.encoding = ‘utf-8‘ soup = BeautifulSoup(res.text, ‘html.parser‘)
import requests from bs4 import BeautifulSoup from selenium import webdriver
res = requests.get(url)
res.encoding = ‘utf-8‘
soup = BeautifulSoup(res.text, ‘html.parser‘)
定时爬取数据:
import time time.sleep(10)
断线重连解决方法:
引入新函数reloading()
def reloading() try: except: reloading()
以上是关于python 爬虫的主要内容,如果未能解决你的问题,请参考以下文章