Scrapy:Google 抓取不起作用 [英] Scrapy: Google Crawl doesn't work
问题描述
当我尝试抓取 Google 以获取搜索结果时,Scrapy 只会生成 Google 主页:http://pastebin.com/FUbvbhN4
When I try to crawl Google for search results, Scrapy just yields the Google home page: http://pastebin.com/FUbvbhN4
这是我的蜘蛛:
import scrapy
class GoogleFinanceSpider(scrapy.Spider):
name = "google"
start_urls = ['http://www.google.com/#q=finance.google.com:+3m+co']
allowed_domains = ['www.google.com']
def parse(self, response):
filename = response.url.split("/")[-2] + '.html'
with open(filename, 'wb') as f:
f.write(response.body)
这个网址作为起始网址有什么问题吗?当我在浏览器中打开它时——通过将它放在地址栏中(而不是通过填写搜索表单)——我得到了有效的搜索结果.
Is there something wrong with this url as a starting url? When I open it in my browser -- by putting it in the address bar (not by filling in the search form) -- I get valid search results.
推荐答案
是的,看起来那个地址正在重定向到主页:
Yes, looks like that address is redirecting to the home page:
带有 scrapy shell 的示例 http://www.google.com/#q=finance.google.com:+3m+co
:
...
[s] request <GET http://www.google.com/#q=finance.google.com:+3m+co>
[s] response <200 http://www.google.com/>
...
检查您的 url 是有道理的,它不包含参数,但是 #q
(不是 url 参数)和浏览器是识别这一点并使其成为谷歌搜索的浏览器,所以它不完全是一个 url 路径.
Checking your url it makes sense, it isn't containing parameters, but #q
(which isn't a url parameter) and the browser is the one recognizing that and making it a google search, so it is not exactly a url path.
正确的谷歌搜索网址是:http://www.google.com/search?q=YOURQUERY
the correct google search url is: http://www.google.com/search?q=YOURQUERY
这篇关于Scrapy:Google 抓取不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!