Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.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_Web Scraping_Beautifulsoup - Fatal编程技术网

Python 易趣网络垃圾

Python 易趣网络垃圾,python,web-scraping,beautifulsoup,Python,Web Scraping,Beautifulsoup,我正试图为列出的每件商品选择一个销售价格,但这是我能得到的最接近的价格 import requests from bs4 import BeautifulSoup url = 'http://www.ebay.co.uk/sch/i.html?_from=R40&_sacat=0&_nkw=graphics%20card&LH_Complete=1&LH_Sold=1&rt=nc&_trksid=p2045573.m1684' r = re

我正试图为列出的每件商品选择一个销售价格,但这是我能得到的最接近的价格

 import requests
 from bs4 import BeautifulSoup

url =  'http://www.ebay.co.uk/sch/i.html?_from=R40&_sacat=0&_nkw=graphics%20card&LH_Complete=1&LH_Sold=1&rt=nc&_trksid=p2045573.m1684'
r = requests.get(url)
soup = BeautifulSoup(r.content, 'html.parser')
Sale_Price = [tag['class'] for tag in soup.find_all("span", class_="bold bidsold")]
print(Sale_Price)
这给了我: [['bold',Bidsaled'],['bold',Bidsaled'],['bold',Bidsaled'],['bold'],
“Bidsaled”]、[“bold”、“Bidsaled”]、[“bold”、“Bidsaled”]、[“bold”、“Bidsaled”]、[“bold”、“Bidsaled”]、[“bold”、“Bidsaled”]、[“bold”、“Bidsaled”]、[“bold”、“Bidsaled”]、[“bold”、“Bidsaled”]、[“bold”、“Bidsaled”]、[“bold”、“Bidsaled”]、[“bold”、“Bidsaled”]、[“Bidsaled”]、[“bold”、“Bidsaled”]、[“Bidsaled”]、[“Bidsaled”]、[“bold”、“Bidsaled”,['bold',Bidsaled'],['bold',Bidsaled'],['bold',Bidsaled'],['bold',Bidsaled'],['bold',Bidsaled'],['bold',Bidsaled'],['bold',Bidsaled'],['bold',Bidsaled'],['bold',Bidsaled'],['bold',Bidsaled'],['bold',Bidsaled'],['bold',Bidsaled'],[',['bold',Bidsaled'],['bold',Bidsaled'],['bold',Bidsaled'],['bold',Bidsaled'],['bold',Bidsaled'],['bold',Bidsaled'],['bold',Bidsaled'],['bold',Bidsaled'],['bold',Bidsaled'],['bold',Bidsaled'],['bold',Bidsaled'],['bold',Bidsaled'],['

您正在存储
类的名称
。价格在
字符串中
。使用
获取文本()
获取
字符串
。字符串包含大量空格或新行,使用
strip()
去除这些空格或新行

import requests
from bs4 import BeautifulSoup

url = 'http://www.ebay.co.uk/sch/i.html?_from=R40&_sacat=0&_nkw=graphics%20card&LH_Complete=1&LH_Sold=1&rt=nc&_trksid=p2045573.m1684'
r = requests.get(url)
soup = BeautifulSoup(r.content, 'html.parser')
Sale_Price =[ tag.get_text().strip() for tag in soup.find_all("span", class_="bold bidsold") ]
print(Sale_Price)
它给出了输出:

['£159.99', '£240.00', '£8.00', '£100.00', '£54.99', '£324.99', '£10.00', '£130.00', '£21.00', '£68.00', '£25.00', '£90.00', '£210.00', '£269.49', '£90.56', '£5.90', '£56.00', '£89.99', '£142.00', '£104.00', '£35.00', '£8.80', '£27.00', '£45.00', '£45.00', '£115.11', '£293.19', '£172.00', '£42.00', '£14.39', '£120.00', '£24.99', '£11.73', '£10.50', '£88.00', '£340.00', '£136.82', '£5.00', '£21.32', '£66.46', '£49.99', '£25.00', '£30.00', '£385.00', '£258.00', '£64.30', '£87.00', '£29.99', '£77.99', '£36.88', '£71.00']
编辑
如果要忽略签名,则取不带第一个字符的字符串

Sale_Price =[ tag.get_text().strip()[1:] for tag in soup.find_all("span", class_="bold bidsold") ]
print(Sale_Price)

这将只存储没有
符号的价格。

这有什么混淆?您选择了搜索的类…请尝试放置
标记['class'以外的其他标记
非常感谢。你知道如何删除每个字符串中的£符号吗?我是一个初学者,不熟悉正则表达式,但通过我的谷歌搜索,我收集了
re.sub(“[£]”,“,”,line)]
不知何故牵涉其中…@JoshDiamond不需要
regex
。我已经更新了代码,看一看。@JoshDiamond你还有什么问题吗?@JoshDiamond只是一个建议,如果ans解决了你的问题,你应该接受它。这样,其他人就可以找到类似问题的有用答案,人们知道你的问题已经解决了。对不起,我很好f a noob:p