Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 试图用lxml抓取一个包含日语字符的网站,但所有字符都得到了匹配。_Python 3.x_Xpath_Unicode_Web Scraping_Lxml - Fatal编程技术网

Python 3.x 试图用lxml抓取一个包含日语字符的网站,但所有字符都得到了匹配。

Python 3.x 试图用lxml抓取一个包含日语字符的网站,但所有字符都得到了匹配。,python-3.x,xpath,unicode,web-scraping,lxml,Python 3.x,Xpath,Unicode,Web Scraping,Lxml,我正试图刮,其中包含许多汉字,每一个都与一个单一的链接图像。到目前为止,我一直在尝试,其中字符表示一个汉字: kanji_page = requests.get('http://www013.upp.so-net.ne.jp/santai/santai.htm') tree = html.fromstring(kanji_page.content) # now contains the whole HTML page page_url = tree.xpath('//a[contains(t

我正试图刮,其中包含许多汉字,每一个都与一个单一的链接图像。到目前为止,我一直在尝试,其中
字符
表示一个汉字:

kanji_page = requests.get('http://www013.upp.so-net.ne.jp/santai/santai.htm')
tree = html.fromstring(kanji_page.content) # now contains the whole HTML page  
page_url = tree.xpath('//a[contains(text(), '+character+')]/@href')
return page_url # returns a list of image URLs
不幸的是,这给了我页面上每个字符的href URL,而不仅仅是匹配的字符。所以说,我进去火, 我只想返回它的URL(
/jpg/0075.jpg
)。知道我做错了什么吗

xpath表达式中缺少

将其更改为:

'//a[contains(text(), "'+character+'")]/@href'

你是如何传递
字符的?
?你能分享一个完整的工作示例吗?当然可以。我现在正在测试它作为一个本地函数,但最终它会从web评论中获取字符。
def ja\u书法搜索(字符):
word=input(“输入:”)
results=ja\u书法\u搜索(word)
print(results)
然后是上面的代码。天哪,我真是个白痴和Python noob。非常感谢!很高兴能提供帮助,如果有帮助,请记住接受!