0
我想廢除谷歌搜索和人們也搜索鏈接。Scrapy谷歌搜索
例如,當你在谷歌和你搜索克里斯託弗nolan。谷歌還製作了「人們也搜索」,其中包括與我們的搜索有關的人的圖片,即克里斯托弗諾蘭。在這種情況下,我們的人也搜索產品(Christian bale,Emma Thomas,Zack Synder等)。我有興趣刮這些數據。
我使用scrapy
框架,並寫了一個簡單的報廢,但它返回一個空的csv數據文件。以下是我迄今爲止的幫助表示讚賞的代碼。希望一切都清楚我想達到的目標。我使用Xpath助手(谷歌應用程序)來幫助找到Xpath。
我的代碼:
# PyGSSpider(spidder folder)
from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from scrapy.selector import Selector
from PyGoogleSearch.items import PyGSItem
import sys
class PyGSSpider(CrawlSpider):
name = "google"
allowed_domains = ["www.google.com"]
start_urls = ["https://www.google.com/#q=christopher+nolan"]
#Extracts Christopher Nolan link
rules = [
Rule(SgmlLinkExtractor(allow=("https://www.google.com/search?q=christpher+noaln&oq=christpher+noaln&aqs")), follow=True),
Rule(SgmlLinkExtractor(allow=()), callback='parse_item')
]
#Parse function for extracting the people also search link.
def parse_item(self,response):
self.log('Hi, this is an item page! %s' % response.url)
sel=Selector(response)
item=PyGSItem()
item['peoplealsosearchfor'] = sel.xpath('//div[@id="cnt"]/@href').extract()
return item
items.py:
from scrapy.item import Item, Field
class PyGSItem(Item):
peoplealsosearchfor = Field()
你究竟在尋求什麼幫助? – jdotjdot
我是如何報廢的人也搜索鏈接 – user3570205