Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/292.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、BeautifulSoup、re从URL获取易趣反馈_Python_Beautifulsoup - Fatal编程技术网

如何使用Python、BeautifulSoup、re从URL获取易趣反馈

如何使用Python、BeautifulSoup、re从URL获取易趣反馈,python,beautifulsoup,Python,Beautifulsoup,有人知道如何使用python3、beautifulsoup、re 我有这个代码,但不容易找到反馈 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&

有人知道如何使用python3、beautifulsoup、re

我有这个代码,但不容易找到反馈

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())

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

您的代码只获取HTML文件的每一行,但您需要访问页面上包含的实际数据。BeautifulSoup可以直接引用div和表格单元格等-只需查看ebay页面的源代码,确定反馈的结构,然后相应地为您的版本编码。