Skip to main content
 首页 » 编程设计

python之如何使用 Python、BeautifulSoup、re 从 URL 获取 eBay 反馈

2024年10月01日7bjzhanghao

有人知道如何使用 python3、beautifulsoup、re...从站点获取 ebay 反馈

我有这段代码,但很难找到反馈。

import urllib.request  
import re 
from bs4 import BeautifulSoup 
 
fhand = urllib.request.urlopen('http://feedback.ebay.com/ws/eBayISAPI.dll?ViewFeedback2&userid=nana90store&iid=-1&de=off&items=25&searchInterval=30&which=positive&interval=30&_trkparms=positive_30') 
 
for line in fhand: 
    print (line.strip()) 
    f=open('feedbacks1.txt','a') 
    f.write(str(line)+'\n') 
    f.close() 
 
 
file = open('feedbacks1.txt', 'r') 
cleaned = open('cleaned.txt', 'w') 
soup = BeautifulSoup(file) 
page = soup.getText() 
letters_only = re.sub("[^a-zA-Z]", " ", page ) 
cleaned.write(str(letters_only)) 

请您参考如下方法:

如果您只关心反馈文本,这可能就是您要找的:

import urllib.request  
import re 
from bs4 import BeautifulSoup 
 
fhand = urllib.request.urlopen('http://feedback.ebay.com/ws/eBayISAPI.dll?ViewFeedback2&userid=nana90store&iid=-1&de=off&items=25&searchInterval=30&which=positive&interval=30&_trkparms=positive_30') 
soup = BeautifulSoup(fhand.read(), 'html.parser') 
table = soup.find(attrs = {'class' : 'FbOuterYukon'}) 
for tr in table.findAll('tr'): 
    if not tr.get('class'): 
        print(list(tr.children)[1].getText()) 

我首先找到带有反馈的表,然后是包含反馈的行(无类),然后是相关行并解析相应的文本。这也可以适应类似的需求。