美文网首页
beautifulsoup、xpath、pyquery总结

beautifulsoup、xpath、pyquery总结

作者: juriau | 来源:发表于2018-10-06 14:54 被阅读6次

1、beautifulsoup

初始化

from bs4 import BeautifulSoup
soup = BeautifulSoup(html, 'html.parser')

用于结构简单清晰的网页,下面两个都适用于复杂的网页


2、xpath

初始化

from lxml import etree
html = etree.HTML(text)

基础规则

image.png

result = html.xpath('/')


3、pyquery

初始化

from pyquery import PyQuery as pq
doc = pq(html)

css选择器

doc.find(selector)


快速获取xpath和css selector的方法

image.png

相关文章

网友评论

      本文标题:beautifulsoup、xpath、pyquery总结

      本文链接:https://www.haomeiwen.com/subject/xirhaftx.html