BeautifulSoup和lxml的基本用法示例

来源:互联网 发布:字体管家软件pc 编辑:程序博客网 时间:2024/05/21 17:13

上一篇里面已经有一种方法了,现在再介绍两种

def get_input(html):    data = {}    soup = BeautifulSoup(html, 'html.parser')    inputs = soup.form.findAll('input')    for input in inputs:        if input.get('name'):            data[input.get('name')] = input.get('value')    return data
from lxml import etreedef get_video_url(page_url):    response = requests.get(page_url).text    selector = etree.HTML(response.encode('utf-8'))    x = selector.xpath('//*[@id="player"]/script/text()')    return re.findall('src="(.*?)&', x[0])[0]
原创粉丝点击