Python 重复的用户名结果

Python 重复的用户名结果,python,web-scraping,xpath,scrapy,web-crawler,Python,Web Scraping,Xpath,Scrapy,Web Crawler,我正在学习在项目中使用Scrapy。当我试图在一个线程中收集帖子的用户名而不是个人信息时,我遇到了一个问题。我用来收集数据的网站是。通过查看页面的HTML,我发现用户名存储在这部分代码中 <a href="https://www.eurobricks.com/forum/index.php?/profile/172939-backtobricks/" data-ipshover="" data-ipshover-target="https

我正在学习在项目中使用Scrapy。当我试图在一个线程中收集帖子的用户名而不是个人信息时,我遇到了一个问题。我用来收集数据的网站是。通过查看页面的HTML,我发现用户名存储在这部分代码中

<a href="https://www.eurobricks.com/forum/index.php?/profile/172939-backtobricks/" data-ipshover="" 
data-ipshover-target="https://www.eurobricks.com/forum/index.php?/profile/172939-backtobricks/&amp;do=hovercard&amp;
referrer=https%253A%252F%252Fwww.eurobricks.com%252Fforum%252Findex.php%253F%252Fforums%252Ftopic%252F172311-lego-star-wars-2020-set-discussion-read-first-post%252F" 
title="Go to BacktoBricks's profile" class="ipsType_break" id="ips_uid_1558_18">BacktoBricks</a>
问题是,结果我得到:

[<Selector xpath="//a[@class='ipsType_break']/text()" data='MKJoshA'>,
 <Selector xpath="//a[@class='ipsType_break']/text()" data='MKJoshA'>,
 <Selector xpath="//a[@class='ipsType_break']/text()" data='JekPorkchops'>,
 <Selector xpath="//a[@class='ipsType_break']/text()" data='JekPorkchops'>,
 <Selector xpath="//a[@class='ipsType_break']/text()" data='Mandalorianknight'>,
 <Selector xpath="//a[@class='ipsType_break']/text()" data='Brick Cucumber'>,
 <Selector xpath="//a[@class='ipsType_break']/text()" data='Brick Cucumber'>,
[,,
,
,
,
,
,
,
正如您所见,用户名有时是双重的,即使用户只发布了一次。
关于如何解决这个问题有什么想法吗?这是唯一有这个问题的信息,因为我也收集了关于这些国家的信息,我没有遇到任何问题。

发生了什么事?

您尝试选择带有[@class='ipsType\u break']模式的每个元素,每个
用户名有多个元素:

尝试使用更具体的
xpath

//strong/a[@class='ipsType_break']/text()

或者,您可以将response.text存储到一个集合中,以获得唯一的结果

names = {} #set of names
for name in names:
   names.add(name) #add element to names
names = {} #set of names
for name in names:
   names.add(name) #add element to names