ValueError: Unicode strings with encoding declaration are not supported.
Please use bytes input or XML fragments without declaration.
When I try parsing this site doesn't work.
When I Try serialized this pagetext I have a error
TypeError: Type 'str' cannot be serialized
from lxml import html
source = 'http://games.chruker.dk/eve_online/item.php?type_id=814'
path = '//*[@id="top"]/table[1]/tbody/tr[1]/td[3]/table'
page = requests.get(source)
pagetext = page.text
parser = html.fromstring(pagetext)
result = parser.xpath(path)
print(result)
I expect a table Requirements like in site: http://games.chruker.dk/eve_online/item.php?type_id=814
Try this:
parser = html.fromstring(bytes(pagetext, encoding='utf8'))
The parse
function the API provides allows you to directly pass in a URL like you have in your source
variable:
from lxml import html
source = 'http://games.chruker.dk/eve_online/item.php?type_id=814'
path = '//*[@id="top"]/table[1]/tbody/tr[1]/td[3]/table'
tree = html.parse(source)
result = tree.xpath(path)
print(result)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With