【Python学习笔记(三)】:爬虫用到的知识点总结
来源:互联网 发布:假面骑士腰带淘宝 编辑:程序博客网 时间:2024/06/11 20:54
持续更新
- 参考文章:https://cuiqingcai.com/2652.html
- selenium :自动化测试工具
- chromedriver.exe(win64位) :带界面的浏览器插件驱动
- PhantomJS :没有界面的浏览器引擎
- BeautifulSoup :解析html
- 官网地址:https://www.crummy.com/software/BeautifulSoup/bs4/doc/index.zh.html
我的完整代码如下,带界面的谷歌浏览器驱动可以运行,但是不带界面的PhantomJS引擎不能工作,报错500
from flask import Flaskfrom bs4 import BeautifulSoupimport urllib.requestimport urllib.parsefrom selenium import webdriverimport timeapp = Flask(__name__)@app.route('/')def hello_world(): url = "http://www.huahaicang.cn/#/size?productId=356530511&brandId=2056402" return getUrl(url)def getUrl(url): browser = webdriver.Chrome() #browser = webdriver.PhantomJS(executable_path="D:\\CompanyProject\\PythonProject\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe") # browser.maximize_window() browser.get(url) time.sleep(1) try: html = browser.page_source soup = BeautifulSoup(html, "lxml") trs = soup.tbody trsContents = trs.contents # 清除列表中的\n元素 while trsContents.count('\n') > 0: trsContents.remove('\n') print(trsContents) dic1 = {} # 循环tr for tr in trsContents: trContents = tr.contents # 清除列表中的\n元素 while trContents.count('\n') > 0: trContents.remove('\n') tdName = trContents[0].string dic1[tdName] = [] # 循环td 取第一个td的值为key,后面的为values; eg:尺码 34/XS 36/S/AS 38/M/AM for td in trContents: if (td != trContents[0]): dic1[tdName].append(td.string) print(dic1) except: print("no contents") return str(dic1)if __name__ == '__main__': app.run()
阅读全文
0 0
- 【Python学习笔记(三)】:爬虫用到的知识点总结
- Python爬虫学习(二)用到的数据结构
- 机器学习中常用到的知识点总结
- Python 爬虫笔记(三)
- python爬虫笔记(三)
- python学习笔记三--爬虫库
- 在学习python网络爬虫时用到的正则表达式
- python的学习知识点总结
- 关于初学python爬虫的一点问题总结(三)
- Python爬虫实践笔记(三)
- python进阶学习笔记(三)数据库支持 (实际工作用到了)
- Python爬虫学习篇——————网络爬虫用到的库
- Python爬虫学习总结
- Python爬虫学习稿(三)
- 学习python写网络爬虫(三)
- 我的Python笔记知识点总结
- Python爬虫学习笔记
- python爬虫学习笔记
- Fragment 生命周期的详情
- ROS -Kinetic<在ubuntu16.04上安装rbx1和arbotix模拟器>
- 用java实现的通用内存分页函数
- SQL事务中锁的用法,与结束进程语句的用法
- JAVA/JS 转码解码(URLEncoder.encode | URLDecoder.decode | encodeURIComponent | decodeURIComponent)
- 【Python学习笔记(三)】:爬虫用到的知识点总结
- 全面解析Java注解
- maven的pom报plugins错误的解决方法.
- Class** 转换成 const Class**的问题
- 无限分类
- 程序员:你为什么要离职?
- 智能蛇
- React Native之报错await is a reserved word
- Select count(*)、Count(1)、Count(0)的区别和执行效率比较