基于python爬虫的几种方法

笑着哭i 提交于 2020-02-19 18:14:07

一  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格式数据

2.dict、str和json之间的转换:https://blog.csdn.net/li532331251/article/details/78203438

二  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交互

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!