⑴ scapy怎麼將響應與請求對應
先去https://pypi.python.org/pypi/scapy/2.3.1網址中下載安裝包
在ubuntu下安裝,解壓縮之後,在相應路徑下執行python setup.py install此時即可使用scapy模塊!
⑵ python安裝scrapy,所需要安裝的包都安裝好了,但是在最後安裝scrapy時,老是出現錯誤
這個問題已經困擾我好幾天了。。。大兄弟後面是怎麼解決這個問題的?
⑶ python3.6安裝Scrapy出現以下錯誤怎麼解決
scapy安裝的錯誤有幾種類型。 因為網路限制,你無法自動下載依賴的庫 因為版本沖突問題,導致你安裝scapy時無法完成安裝,或者是安裝無法正確使用 因為編譯的位數不同64位和32位不同,
⑷ 如何python 中運行scapy shell
啟用shell
可以使用如下命令啟用shell
[python] view plain
scrapy shell <url>
其中<url>就是你想抓取的頁面url
使用shell
Scrapy shell可以看成是一個內置了幾個有用的功能函數的python控制台程序。
功能函數
shelp() - 輸出一系列可用的對象和函數
fetch(request_or_url)-從給定的url或既有的request請求對象重新生成response對象,並更新原有的相關對象
view(response)-使用瀏覽器打開原有的response對象(換句話說就是html頁面)
Scrapy 對象
使用Scrapy shell下載指定頁面的時候,會生成一些可用的對象,比如Response對象和Selector對象(Html和XML均適用)
這些可用的對象有:
crawler - 當前的Crawler對象
spider
request - 最後獲取頁面的請求對象
response - 一個包含最後獲取頁面的響應對象
sel - 最新下載頁面的Selector對象
settings - 當前的Scrapy settings
Scrapy shell例子
以我的個人博客作為測試:http://blog.csdn.net/php_fly
首先,我們啟動shell
[python] view plain
scrapy shell http://blog.csdn.net/php_fly --nolog
以上命令執行後,會使用Scrapy downloader下載指定url的頁面數據,並且列印出可用的對象和函數列表
[python] view plain
[s] Available Scrapy objects:
[s] crawler <scrapy.crawler.Crawler object at 0x0000000002AEF7B8>
[s] item {}
[s] request <GET http://blog.csdn.net/php_fly>
[s] response <200 http://blog.csdn.net/php_fly>
[s] sel <Selector xpath=None data=u'<html xmlns="http://www.w3.org/1999/xhtm'>
[s] settings <CrawlerSettings mole=None>
[s] spider <Spider 'default' at 0x4cdb940>
[s] Useful shortcuts:
[s] shelp() Shell help (print this help)
[s] fetch(req_or_url) Fetch request (or URL) and update local objects
[s] view(response) View response in a browser
獲取曾是土木人博客的文章列表超鏈接
[python] view plain
In [9]: sel.xpath("//span[@class='link_title']/a/@href").extract()
Out[9]:
[u'/php_fly/article/details/19364913',
u'/php_fly/article/details/18155421',
u'/php_fly/article/details/17629021',
u'/php_fly/article/details/17619689',
u'/php_fly/article/details/17386163',
u'/php_fly/article/details/17266889',
u'/php_fly/article/details/17172381',
u'/php_fly/article/details/17171985',
u'/php_fly/article/details/17145295',
u'/php_fly/article/details/17122961',
u'/php_fly/article/details/17117891',
u'/php_fly/article/details/14533681',
u'/php_fly/article/details/13162011',
u'/php_fly/article/details/12658277',
u'/php_fly/article/details/12528391',
u'/php_fly/article/details/12421473',
u'/php_fly/article/details/12319943',
u'/php_fly/article/details/12293587',
u'/php_fly/article/details/12293381',
u'/php_fly/article/details/12289803']
修改scrapy shell的請求方式:
[python] view plain
>>> request = request.replace(method="POST")
>>> fetch(request)
[s] Available Scrapy objects:
[s] crawler <scrapy.crawler.Crawler object at 0x1e16b50>
...
從Spider中調用Scrapy shell
在爬蟲運行過程中,有時需要檢查某個響應是否是你所期望的。
這個需求可以通過scrapy.shell.inspect_response函數進行實現
以下是一個關於如何從spider中調用scrapy shell的例子
[python] view plain
from scrapy.spider import Spider
class MySpider(Spider):
name = "myspider"
start_urls = [
"http://example.com",
"http://example.org",
"http://example.net",
]
def parse(self, response):
# We want to inspect one specific response.
if ".org" in response.url:
from scrapy.shell import inspect_response
inspect_response(response)
# Rest of parsing code.
當你啟動爬蟲的時候,控制台將列印出類似如下的信息
[python] view plain
2014-02-20 17:48:31-0400 [myspider] DEBUG: Crawled (200) <GET http://example.com> (referer: None)
2014-02-20 17:48:31-0400 [myspider] DEBUG: Crawled (200) <GET http://example.org> (referer: None)
[s] Available Scrapy objects:
[s] crawler <scrapy.crawler.Crawler object at 0x1e16b50>
...
>>> response.url
'http://example.org'
注意:當Scrapy engine被scrapy shell佔用的時候,Scrapy shell中的fetch函數是無法使用的。 然而,當你退出Scrapy shell的時候,蜘蛛將從停止的地方繼續爬行
⑸ 求教python程序調用scapy模塊的問題
你把python27.dll復製成python27_d.dll就可以了。然後把dll放到windows/system32目錄。或者是程序執行目錄中。 原因是你的程序是debug版本的。你編譯成release版本就沒有這個問題了。 你編譯能成功可見python27的lib應該連接成了。
⑹ python,scapy,rdpcap模塊缺失問題
你可以參考一下:
Python 2.7.3 (default, Apr 10 2013, 05:09:49)
[GCC 4.7.2] on linux2
Type "help", "right", "credits" or "license" for more information.
>>> from scapy.all import *
WARNING: No route found for IPv6 destination :: (no default route?)
>>> IP()
<IP |>
>>> target="ww w.b ai.c om"
>>> target="ww w.d u.co m/30"
>>> ip=IP(dst=target)
>>> ip
<IP dst=Net('ww w.ba i.c om/30') |>
>>> [p for p in ip]
[<IP dst=61.135.169.104 |>, <IP dst=61.135.169.105 |>, <IP dst=61.135.169.106 |>, <IP dst=61.135.169.107 |>]
>>>
⑺ 如何在centos中安裝pythonscapy
在CentOs6.5下安裝Python2.7.6和Scrapy
總在網上看大家的安裝教程,這回自己也貢獻一份!!!
和民航大學合作項目,去給人家裝環境,連簡單的Scrapy都沒裝上,雖然有對方硬體設施坑爹的因素,但主要還是自己准備不充分。
一份好的安裝文檔應該是可以完美重現的。
所以做了下面這份:
我按照這套方法連著重裝了四次,如果各位直接復制命令,應該是一點問題都沒有。安裝成功的樣子見那兩張截圖。
對了,確保電腦能上網,滑鼠能用,哈哈
1.#su – root
2.#yum install gcc zlib-devel bzip2-devel openssl-devel ncurses-devel libffi-devel libxslt-devel libxml2-devel sqlite-devel
3.#cd /usr
4.安裝Python
#wget python/2.7.6/Python-2.7.6.tar.xz
#xz -d Python-2.7.6.tar.xz
#tar xvf Python-2.7.6.tar
#cd Python-2.7.6
#./configure
#vim Moles/Setup
找到下面這句,去掉注釋
#zlib zlibmole.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
編譯安裝:make & make install
5.修改Python鏈接
#/usr/local/bin/python2.7 -V
#mv /usr/bin/python /usr/bin/python.bak
# ln -s /usr/local/bin/python2.7 /usr/bin/python
6.#vim /usr/bin/yum
在打開的文件里的頭一行,也就是指定python環境的那行代碼,修改成:
#!/usr/bin/python2.6
7.#wget --no-check-certificate
#python ez_setup.py
8.#wget --no-check-certificate
#python get-pip.py
9.#pip install scrapy
10.#scrapy
11.建立測試腳本
12.# cat > myspider.py <<EOF
from scrapy import Spider, Item, Field
class Post(Item):
title = Field()
class BlogSpider(Spider):
name, start_urls = 'blogspider', ['wsblog/']
def parse(self, response):
return [Post(title=e.extract()) for e in response.css("h2 a::text")]
EOF
13.試建工程
scrapy startproject tutorial
⑻ Python安裝Scrapy出現以下錯誤怎麼辦
scapy安裝的錯誤有幾種類型。
因為網路限制,你無法自動下載依賴的庫
因為版本沖突問題,導致你安裝scapy時無法完成安裝,或者是安裝無法正確使用
因為編譯的位數不同64位和32位不同,導致的問題
解決辦法:
簡單的解決辦法。如果scrapy對你很重要。重新安裝一套python2.7然後從頭安裝scrapy,可以從pypi網站上下載。也可以從unofficial來源,一口氣安裝好的包。
耐心的解決辦法。把scrapy的源碼拿過來,執行python setup.py install,遇到哪個包不好用,就替換掉。辦法是將那個包的源代碼拿過來,先刪除site-packages里的相應包,再手工執行python setup.py install。要有心理准備,很可能需要vc++ 2010的編譯器。
最簡單的辦法,使用pip install scrapy。 如果你是在ubuntu下面apt-get install python-scrapy就搞定了。