broswer = webdriver.Firefox() broswer.get("https://www.smzdm.com/p/20765776/#hfeeds") # self.logger.info(broswer.page_source) goods_scrapy_selector = Selector(text=broswer.page_source) title_selector = goods_scrapy_selector.css(".J_title") title = title_selector.get() self.logger.info(title) broswer.get("https://www.smzdm.com/p/20769796/#hfeeds") goods_scrapy_selector = Selector(text=broswer.page_source) title_selector = goods_scrapy_selector.css(".J_title") title = title_selector.get()
不知道问什么,broswer只有在执行第一句的get时浏览器才会去加载页面,第二句不会去加载导致第二句的title是第一个地址的值。后来发现是url中#hfeeds这个锚的问题,去掉#feeds就好了,具体什么原因还不清楚。