我要抓取 html 内容http://ntry.com/#/scores/named_ladder/main.php http://ntry.com/#/scores/named_ladder/main.php with Scrapy
.
但是,由于该网站的Javascript
使用和 # ,我想我必须使用Selenium
(Python
) also.
我想编写自己的代码,但我对编程很陌生,所以我想我需要帮助;
我想先进入 ntry.com,然后移至http://ntry.com/#/scores/named_ladder/main.php http://ntry.com/#/scores/named_ladder/main.php通过单击名为的锚点
<body>
<div id="wrap">
<div id="container">
<div id="content">
<a href="/scores/named_ladder/main.php">사다리</a>
</div>
</div>
</div>
</body>
然后我想使用以下方法在更改页面上抓取 htmlScrapy
.
我怎样才能做一个selenium
-混合Scrapy
蜘蛛?
我安装了 Selenium,然后加载了 PhantomJS 模块,它运行得很好。
这是你可以尝试的
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
class FormSpider(Spider):
name = "form"
def __init__(self):
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = ("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36")
self.driver = webdriver.PhantomJS(desired_capabilities=dcap, service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any', '--web-security=false'])
self.driver.set_window_size(1366,768)
def parse_page(self, response):
self.driver.get(response.url)
cookies_list = self.driver.get_cookies()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)