Html 如何获得;275,47“;值(美化组、蟒蛇3)

Html 如何获得;275,47“;值(美化组、蟒蛇3),html,python-3.x,beautifulsoup,python-requests,Html,Python 3.x,Beautifulsoup,Python Requests,我是一个新的网页抓取,所以我需要你的帮助。 我有一个html代码(看看),我想得到这个特定的值-->“275,47”。 我写下了这段代码,但出了点问题。。。请帮帮我!:) 所以,你很接近!正在引发错误,因为变量“value”没有名为string的属性。值当前是项的列表。您希望迭代所有的锚,并找到您正在寻找的锚 我的建议是: import requests from bs4 import BeautifulSoup as bs url="https://www.skroutz.gr/s/1150

我是一个新的网页抓取,所以我需要你的帮助。 我有一个html代码(看看),我想得到这个特定的值-->“275,47”。 我写下了这段代码,但出了点问题。。。请帮帮我!:)


所以,你很接近!正在引发错误,因为变量“value”没有名为string的属性。值当前是项的列表。您希望迭代所有的锚,并找到您正在寻找的锚

我的建议是:

import requests
from bs4 import BeautifulSoup as bs

url="https://www.skroutz.gr/s/11504255/Apple-iPhone-SE-32GB.html"
page=requests.get(url)
soup=bs(page.text,"html.parser")

value=soup.find_all("a")

for item in value:
    if '30871132' in item.get('href'):
        print item.text
item将是我们在循环中迭代的当前锚定标记

我们可以使用.get方法获取它的href属性(或任何属性)


然后,我们检查href中是否有“308711332”,如果有,请打印文本。

感谢您对我的问题的快速回复!您的信息对我很有价值:)
import requests
from bs4 import BeautifulSoup as bs

url="https://www.skroutz.gr/s/11504255/Apple-iPhone-SE-32GB.html"
page=requests.get(url)
soup=bs(page.text,"html.parser")

value=soup.find_all("a")

for item in value:
    if '30871132' in item.get('href'):
        print item.text