niklasb / webkit-server

[not actively maintained] The C++ webkit-server from capybara-webkit with useful extensions and Python bindings
MIT License
48 stars 38 forks source link

Encode the issue_command args before setting their length. #31

Open pjrobertson opened 7 years ago

pjrobertson commented 7 years ago

Fixes #30

See my comments in #30 for more info about this.

Perhaps a unit test that should be set up:

import dryscrape
import sys

if 'linux' in sys.platform:
    # start xvfb in case no X is running. Make sure xvfb 
    # is installed, otherwise this won't work!
    dryscrape.start_xvfb()

search_term = '西安 some non-latin characters 北京'

# set up a web scraping session
sess = dryscrape.Session(base_url = 'http://google.com')

# we don't need images
sess.set_attribute('auto_load_images', False)

# visit homepage and search for a term
sess.visit('/')
q = sess.at_xpath('//*[@name="q"]')
q.set(search_term)
// issue another command to the driver, to make sure the above command worked successfully (len was set properly)
q = sess.at_xpath("//*[@name="btnK"]')
q.click()

# extract all links
for link in sess.xpath('//a[@href]'):
  print(link['href'])

# save a screenshot of the web page
sess.render('google.png')
print("Screenshot written to 'google.png'")