0

我在使用'class_= "count"in时遇到问题'class_= "count"' dude = factory(url, cookies, 'span', 'class_= "count"', arg3='span')。当它到达时,next = soup.find_all(arg1, arg2)它不会正确扩展。next = soup.find_all(arg1,'class_= "count")工作正常,但不是 arg2 数据成员字符串。

import sqlite3 
import sys
import urllib2
import requests
from bs4 import BeautifulSoup


def get_session_info(cookie_file):
    con = sqlite3.connect(cookie_file)
    cur = con.cursor()


    #cur.execute('select value from cookies where name="_zendesk_cookie"')
    #data = cur.fetchone()
    #cookie1 = data[0]
    #cookie1 = str(cookie1)

    cur.execute('select value from cookies where name="_zendesk_shared_session"')
    data = cur.fetchone()
    cookie2= data[0]
    cookie2= str(cookie2)

    #cookies = dict(_zendesk_cookie=cookie1)
    cookies = dict(_zendesk_shared_session=cookie2)
    return cookies

def factory(url, cookies, arg1, arg2, arg3 = None):
    bob = requests.get(url, cookies=cookies)
    soup = BeautifulSoup(bob.text)
    if arg3:
        next = soup.find_all(arg1, arg2)
    print "hit1"
    print next
    else:
        next = soup.find_all(arg1)

    soup = BeautifulSoup(str(next))
    yo = soup.find("span")
    print type(yo)
    yo = yo.get_text()
    return yo

def main():
    cookie_database = "/home/one/.config/chromium/Default/Cookies"
    url = "https://theurl"
    #MUST RUN CHROMIUM AND MUST RUN ONE ZENDESK SESSION
    #FROM BROWSER TO ESTABLISH COOKIES IN 
    #CHROMIUMS COOKIE DATABASE
    cookies = get_session_info(cookie_database)

    dude = factory(url, cookies, 'span', 'class_= "count"', arg3='span')
    print dude

main()
4

1 回答 1

1
#yours
arg1=..., 'class_= "count"', arg3=...

#should be
arg1=..., 'count', arg3=...

#yours
next = soup.find_all(arg1, arg2)

#should be
next = soup.find_all(arg1, class_ = arg2)
于 2013-08-25T01:08:33.997 回答