代码
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片段:
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
我这边是可以的,不知道会不会是编码的问,或者是lxml扩展的问题
换个解析器试试
soup = BeautifulSoup(html, 'html.parser')pyquery,不二之选, 语法和jquery一样