Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.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美化组搜索问题_Python_Python 3.x_Beautifulsoup - Fatal编程技术网

Python美化组搜索问题

Python美化组搜索问题,python,python-3.x,beautifulsoup,Python,Python 3.x,Beautifulsoup,我有问题让bs找到这篇文章。我想这是因为页面上的文字周围有额外的引号。有人告诉我这是因为这门课实际上是空白的。如果是这样的话,那么对我如何构建搜索有什么建议吗? 网站上的实际文本: 我的代码(我尝试了几种变体):soup.find_all('span',{'class':'“data product price=“”}) 我也试着做一个常规的搜索,但我做得不对。有什么建议吗?或者我应该使用bs以外的东西吗 编辑以包含完整代码: import bs4 import requests

我有问题让bs找到这篇文章。我想这是因为页面上的文字周围有额外的引号。有人告诉我这是因为这门课实际上是空白的。如果是这样的话,那么对我如何构建搜索有什么建议吗? 网站上的实际文本:

我的代码(我尝试了几种变体):
soup.find_all('span',{'class':'“data product price=“”})

我也试着做一个常规的搜索,但我做得不对。有什么建议吗?或者我应该使用bs以外的东西吗

编辑以包含完整代码:

    import bs4
    import requests
    from bs4 import BeautifulSoup
    r=requests.get('https://www.gouletpens.com/products/twsbi-diamond-580- 
    fountain-pen-clear?variant=11884892028971')
    soup = bs4.BeautifulSoup(r.text, features="html.parser")
    print(soup)     
    #soup.find_all('span',{'class' : '" data-product-price="'})
    #soup.find_all('span',{'class' : 'data-product-price'})[0].text

查看URL后,您可以使用CSS选择器选择价格:

import requests
from bs4 import BeautifulSoup

url = 'https://www.gouletpens.com/products/twsbi-diamond-580-fountain-pen-clear?variant=11884892028971'
soup = BeautifulSoup(requests.get(url).content, 'html.parser')

print(soup.select_one('span[data-product-price]').get_text(strip=True))
印刷品:

$50.00

或:使用
bs4
API(设置
{'data-product-price':True}
以搜索具有此属性的标记,而不考虑其中的值:

print(soup.find('span', {'data-product-price':True}).get_text(strip=True))

我想这是因为类是空的。你看不到,但网站上的文本如下:
网站上的实际文本:你忘了包含文本了吗?请分享所有相关的代码和数据。请看:。@Andrej Kesely这是URL:@Boendal我不确定它为什么没有出现,但我已经修复了。谢谢!非常感谢!!!Thi现在我知道我需要花更多的时间学习什么了。我真的很感谢你的帮助。