python爬虫有几种方法_基于Python爬虫的几种方法,python
生活随笔
收集整理的這篇文章主要介紹了
python爬虫有几种方法_基于Python爬虫的几种方法,python
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一? requests,json格式數據
#1.獲取鏈接
url =
#2.獲取響應
response = requests.get(url)
response = response.content.decode()
#3.提取數據
response = json.loads(response)??? ?????# json字符串→python字典
#4.保存數據
f.write(json.dumps(content)) ???????????# python字典→json字符串,字典不能寫入文件
注:
1.可用user-agent-switcher將瀏覽器切換到手機模式,獲取json格式數據
二? selenium
#1.獲取鏈接
url =
#2.獲取響應
driver=webdriver.Chrome()
response = driver.get(url)
#3.提取數據
方法一:xml
response = driver.page_source
response = etree.HTML(response)
方法二:selenium,可翻頁、點擊等操作
response = driver.find_element_by_
#4.保存數據
三? pyppeteer
四? python與mongodb交互
總結
以上是生活随笔為你收集整理的python爬虫有几种方法_基于Python爬虫的几种方法,python的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 苹果手机java_iphone手机,苹果
- 下一篇: Python中的线程、进程、协程以及区别