Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python 3.5 find_all语句_Python_Beautifulsoup - Fatal编程技术网

python 3.5 find_all语句

python 3.5 find_all语句,python,beautifulsoup,Python,Beautifulsoup,这里需要帮助。我正试图打印文本“Whirlpool®18 cu.Ft.Top冷冻冰箱-WRT148FZDB”,但尚未找到find_all语句中的正确结构。我现在调用find_all,代码如下,但我知道这是错误的 g6_data = soup.find_all("div", {"class": "product_name"}) 下面的代码是我试图从中提取信息的代码 感谢您的帮助。谢谢 <div class="product_info"> <div id="pr

这里需要帮助。我正试图打印文本“Whirlpool®18 cu.Ft.Top冷冻冰箱-WRT148FZDB”,但尚未找到find_all语句中的正确结构。我现在调用find_all,代码如下,但我知道这是错误的

g6_data = soup.find_all("div", {"class": "product_name"})
下面的代码是我试图从中提取信息的代码

感谢您的帮助。谢谢

<div class="product_info">

        <div id="product_name_7267017" class="product_name">

            <a aria-hidden="true" tabindex="-1" id="CatalogEntryViewDetailsLink_7267017" href="http://www.sears.ca/product/whirlpool-18-cuft-top-freezer-refrigerator-wrt148fzdb/646-000153197-WRT148FZDB"><span itemprop="name">Whirlpool® 18 cu.Ft. Top Freezer Refrigerator  - WRT148FZDB</span></a>
            <input type="hidden" id="ProductInfoName_7267017" value="Whirlpool® 18 cu.Ft. Top Freezer Refrigerator  - WRT148FZDB">
        </div>

您需要从div内的锚定标记中提取文本,您可以使用css选择器:

import requests
from bs4 import BeautifulSoup

soup = BeautifulSoup(requests.get("http://www.sears.ca/catalog/appliances-fridges-freezers-refrigerators-top-freezer-en-wp-836#facet:&productBeginIndex:0&orderBy:&pageView:grid&minPrice:&maxPrice:&pageSize:100&").text)


for a in soup.select("div.product_name a"):
    print(a.text)

您需要从div内的锚定标记中提取文本,您可以使用css选择器:

import requests
from bs4 import BeautifulSoup

soup = BeautifulSoup(requests.get("http://www.sears.ca/catalog/appliances-fridges-freezers-refrigerators-top-freezer-en-wp-836#facet:&productBeginIndex:0&orderBy:&pageView:grid&minPrice:&maxPrice:&pageSize:100&").text)


for a in soup.select("div.product_name a"):
    print(a.text)

为什么错了?当你尝试这样做时会发生什么?吹毛求疵,但这是一种方法(一种函数类型),而不是一条语句。你能提供一个链接到你从中获取html的页面吗?我知道它在西尔斯的某个地方,但到底是哪一页?这是我要刮的那一页,为什么它错了?当你尝试这样做时会发生什么?吹毛求疵,但这是一种方法(一种函数类型),而不是一条语句。你能提供一个链接到你从中获取html的页面吗?我知道它在西尔斯的某个地方,但确切的说是哪一页,这就是我要刮的那一页,谢谢,那就行了。刚才我得用另一种方法来确定格式谢谢,行了。刚才我必须用另一种方法来确定格式