我对编程非常陌生,如果这是新手问题,我深表歉意。我是一名研究人员,我一直在构建蜘蛛,让我能够抓取游戏论坛IGN的特定搜索结果。第一个爬行器收集搜索结果中的每个条目以及URL,然后第二个爬行器为内容抓取每个URL
问题在于,IGN将与特定帖子相关联的URL重定向到一个新URL,该URL在地址末尾包含一个#书签。这允许页面的访问者直接跳转到有问题的帖子,但我希望我的蜘蛛能够爬过整个帖子。此外,我的爬行器在重定向后出现(911)错误,并且没有返回任何数据。检索到的唯一数据来自直接链接到线程而不是帖子的任何搜索结果
我完全被难住了,也很困惑,所以任何帮助都会令人惊讶!两个蜘蛛都附在下面
蜘蛛网1:
myURLs = [] baselineURL = "https://www.ign.com/boards/search/186716896/?q=broforce&o=date&page=" for counter in range (1,5):
myURLs.append(baselineURL + str(counter))
class BroforceIGNScraper(scrapy.Spider):
name = "foundation"
start_urls = myURLs
def parse(self,response):
for post in response.css("div.main"):
yield {
'title': post.css("h3.title a::text").extract_first(),
'author': post.css("div.meta a.username::text").extract_first(),
'URL': post.css('h3 a').xpath('@href').extract_first(),
}
蜘蛛网2:
URLlist = []
baseURL = "https://www.ign.com/boards/"
import csv
with open('BroforceIGNbase.csv', 'r', newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
URLlist.append(baseURL + row['URL'])
class BroforceIGNScraper(scrapy.Spider):
name = "posts2"
start_urls = URLlist
# handle_httpstatus_list = [301]
def parse(self,response):
for post in response.css(".messageList"):
yield {
'URL': response.url,
'content': post.css(".messageContent article").extract_first(),
'commentauthor': post.css("div.messageMeta a::text").extract_first(),
'commentDateTime': post.css('div.messageMeta a span.DateTime').xpath('@title').extract_first(),
}
目前没有回答
相关问题 更多 >
编程相关推荐