小编qma*_*ruf的帖子

使用curl单击javascript按钮

我已经使用curl解析了一个页面,它包含一些复选框以及“全选”和“提交”按钮。单击该按钮将选中每个复选框。“全选”按钮将触发一个javascript函数,该函数实际上会选中所有复选框。

现在我需要单击“全选”和“提交”按钮。我该怎么做?

这是按钮代码:

input type="button" onclick="SelectAll(137)" value="Select All"
Run Code Online (Sandbox Code Playgroud)

这是js函数:

function SelectAll(n)
{
    for(i=0;i<n;i++)
    document.getElementById("ch"+i).checked=true;
} 
Run Code Online (Sandbox Code Playgroud)

javascript php curl

3
推荐指数
1
解决办法
9511
查看次数

py2neo,neo4j:如何在两个现有节点之间建立关系

我正在按照本教程使用python访问neo4j db.根据这个教程,我在4个节点之间创建了2个关系.代码如下

alice, bob, rel = graph_db.create(
                      {"name": "Alice"}, {"name": "Bob"},
                      (0, "KNOWS", 1))
dev, carol, rel = graph_db.create(
                      {"name": "Dev"}, {"name": "Carol Smith"},
                      (0, "KNOWS", 1))
Run Code Online (Sandbox Code Playgroud)

如何在不创建新节点的情况下创建alice和carol之间的关系?

下面的代码片段在该教程中给出,用于创建现有节点之间的关系.在上面的例子中不确定如何使用它.

ref_node = graph_db.get_reference_node()
alice, rel = graph_db.create(
                {"name": "Alice"}, (ref_node, "PERSON", 0))
Run Code Online (Sandbox Code Playgroud)

当我尝试执行时

ref_node = graph_db.get_reference_node()
Run Code Online (Sandbox Code Playgroud)

我收到以下错误.

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'GraphDatabaseService' object has no attribute 'get_reference_node'
Run Code Online (Sandbox Code Playgroud)

有什么建议可以解决这个问题吗?

python neo4j py2neo

2
推荐指数
1
解决办法
7367
查看次数

为什么python scrapy显示"twisted.internet.error.TimeoutError"错误

我试图使用python scrapy废弃页面.经过一些报废操作后,scrapy正在戒烟

twisted.internet.error.TimeoutError error
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

#infobel_spider.py
from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector
from scrapy.http.request import Request
from scrapy.http import FormRequest
from infobel.items import InfobelItem
import sys
import xlwt
import re
import codecs    

class InfobelSpider(BaseSpider):
    name = 'infobel'
    start_urls = ['http://www.infobel.com/en/italy/business/20300/accessories']

    def parse(self,response):

        hxs = HtmlXPathSelector(response)

        next_page = hxs.select("//a[@id='Pagination1_lnkNextRec']/@href").extract()
        if not not next_page:
             yield Request("http://www.infobel.com"+next_page[0],self.parse)

        qs = hxs.select("//div[@class='result-item clearfix']")
        items = []
        for q in qs:
            item = InfobelItem()
            item['name'] = q.select('div/div/h2/a/span/text()').extract()
            item['address'] = q.select('div/div/ul/li[1]/div/span/text()').extract()
            item['phone'] = q.select('div/div/ul/li[2]/div/text()').extract()
            item['email'] …
Run Code Online (Sandbox Code Playgroud)

python scrapy

1
推荐指数
1
解决办法
4282
查看次数

python scrapy如何删除额外的解析字符

在使用scrapy的解析过程中,我找到了这个输出

[u'TARTARINI AUTO SPA(CENTRALINO SELEZIONE PASSANTE)',"[u'VCBONAZZI\xa043',u'40013',u'CASTEL MAGGIORE']",[u'0516322411'],[u'info @ tartariniauto.它'],[u'CARS(LPG INSTALLERS)'],[u'track.aspx?id = 0&url = http://www.tartariniauto.it']

如你所见,还有一些额外的角色

你'\ xa043"'[]

我不想要的.我怎样才能删除这些?此字符串中还有5个项目.我希望字符串看起来像这样:

item1,item2,item3,item4,item5

这是我的pipelines.py代码

from scrapy.contrib.loader import ItemLoader
from scrapy.contrib.loader.processor import TakeFirst, MapCompose, Join
import re
import json
import csv

class InfobelPipeline(object):
    def __init__(self):
      self.file = csv.writer(open('items.csv','wb'))
    def process_item(self, item, spider):
      name = item['name']
      address = item['address']
      phone = item['phone']
      email = item['email']
      category = item['category']
      website = item['website']
      self.file.writerow((name,address,phone,email,category,website))
    return item
Run Code Online (Sandbox Code Playgroud)

谢谢

python scrapy

1
推荐指数
1
解决办法
2443
查看次数

标签 统计

python ×3

scrapy ×2

curl ×1

javascript ×1

neo4j ×1

php ×1

py2neo ×1