首页 > BeautifulSoup python 爬虫无法搜索目标标签

BeautifulSoup python 爬虫无法搜索目标标签

代码

import requests
from bs4 import BeautifulSoup

url = 'http://product.pconline.com.cn/mobile/'
response = requests.get(url)
html = response.text
print html

soup = BeautifulSoup(html, 'lxml')
site = soup.find_all('img', class_="pic")
print site

目标网站:http://product.pconline.com.cn/mobile/
打算爬取的是手机图片标签,运行上面这段代码后打印的site得到是空的。

图片部分html片段:

<img class="pic" alt="华为Mate8/3GB+32GB版" title="麒麟950处理器、6寸超大屏、超高屏占比、超窄边框,3GB+32GB全网通版本" src="http://img.pconline.com.cn/images/product/5807/580761/q_sn8.jpg" height="150" width="200">

pyquery,不二之选, 语法和jquery一样

import requests, pyquery
url = 'http://product.pconline.com.cn/mobile/'
r = requests.get(url)

html = r.text.replace('#src', 'jsrc')
Q = pyquery.PyQuery(html)

for _ in Q('img.pic'):
    print Q(_).attr('jsrc'), Q(_).attr('alt'), Q(_).attr('title')

换个解析器试试
soup = BeautifulSoup(html, 'html.parser')


我这边是可以的,不知道会不会是编码的问,或者是lxml扩展的问题

【热门文章】
【热门文章】