title: Can't figure out how to 'grab' an <a> tag with a class name with Scrapy
body: <p>I'm scraping some chinese websites for a research project and have run into a problem that I just can't crack. Using scrapy, I'm trying to follow the link in an  tag with the class name "up" (the tag is one of many tags in a nav bar). The problem is that neither CSS or Xpath selectors are able to "grab" the tag. I'm able to fetch it's parent div tag just fine, but when I try to access its children, scrapy returns an empty list. Here is the structure of the parent div and it's child tags:</p>
  
  <pre><code>    &lt;div class="xz-page clearfix" style="margin-left:160px;"&gt;
          &lt;script type="text/javascript"&gt; ... &lt;/script&gt;
          &lt;a class="pre" href="javascript:void(0)" style="width:40px"&gt;上一页&lt;/a&gt;
          &lt;a class="num sel" href="javascript:void(0)"&gt;1&lt;/a&gt;
          &lt;a class="num" href="index_1.html"&gt;2&lt;/a&gt;
          &lt;a class="num" href="index_2.html"&gt;3&lt;/a&gt;
          &lt;a href="javascript:void(0)" style="border:none"&gt;...&lt;/a&gt;
          &lt;a class="num" href="index_697.html"&gt;698&lt;/a&gt;
          &lt;a class="num" href="index_698.html"&gt;699&lt;/a&gt;
          &lt;a class="up" href="index_1.html" style="width:40px"&gt;下一页&lt;/a&gt;&amp;nbsp;
      &lt;/div&gt;
  </code></pre>
  
  <p>The link I'm trying to grab is the one in the last .</p>
  
  <p>When I use the selector:</p>
  
  <pre class="lang-py prettyprint-override"><code>next_page = response.xpath('//div[@class = "xz-page clearfix"])
  </code></pre>
  
  <p>It returns this:</p>
  
  <pre><code>[&lt;Selector xpath='//div[@class = "xz-page clearfix"]' data='&lt;div class="xz-pageclearfix" style="mar'&gt;]
  </code></pre>
  
  <p>But when I try to access the  tag with this:</p>
  
  <pre class="lang-py prettyprint-override"><code>next_page = response.xpath('//div[@class = "xz-page clearfix"]/a[@class ="up"]')
  </code></pre>
  
  <p>Or just this in an attempt to grab all  children:</p>
  
  <pre class="lang-py prettyprint-override"><code>next_page = response.xpath('//div[@class = "xz-page clearfix"]/a')
  </code></pre>
  
  <p>It returns an empty list []</p>
  
  <p>I've tried multiple iterations of the above selector, and each time I get an empty list.</p>
  
  <p>Even just trying to get the tag with this:</p>
  
  <pre class="lang-py prettyprint-override"><code>next_page = response.xpath('//a[@class = "up"]')
  </code></pre>
  
  <p>Returns an empty list</p>
  
  <p>I suspect it has something to do with the script tag.</p>
  
  <p>The script inside the script tag is as follows:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function createPageHTML(_nPageCount, _nCurrIndex, _sPageName, _sPageExt){
    if(_nPageCount == null || _nPageCount&lt;=1){
      return;
    }
  
    var nCurrIndex = _nCurrIndex || 0;
    // 1 输出首页和上一页
    // 1.1 当前页是首页
    if(nCurrIndex == 0){
      document.write("&lt;a class=\"pre\" href=\"javascript:void(0)\" style=\"width:40px\"&gt;上一页&lt;/a&gt;");
      document.write("&lt;a class=\"num sel\" href=\"javascript:void(0)\"&gt;1&lt;/a&gt;");
    }
    //1.2 当前页不是首页
    else{
      var nPreIndex = nCurrIndex - 1;
      var sPreFileExt = nPreIndex == 0 ? "" : ("_" + nPreIndex);
  
      document.write("&lt;a class=\"next\" href=\"" + _sPageName + sPreFileExt + "."+_sPageExt+"\" style=\"width:40px\"&gt;上一页&lt;/a&gt;");
      document.write("&lt;a class=\"num\" href=\""+_sPageName+"."+_sPageExt+"\"&gt;1&lt;/a&gt;");
    }
  
    // 2 输出中间分页
    var flag1=true;
    var flag2=true;
  
    for(var i=1; i&lt;_nPageCount; i++){
  
      if(i-nCurrIndex&lt;3&amp;&amp;nCurrIndex-i&lt;3||i&lt;2||_nPageCount-i&lt;3){
        if(nCurrIndex == i)
          document.write("&lt;a class=\"num sel\" href=\"javascript:void(0)\"&gt;"+(i+1)+"&lt;/a&gt;");
        else
          document.write("&lt;a class=\"num\" href=\""+_sPageName+"_" + i + "."+_sPageExt+"\"&gt;"+(i+1)+"&lt;/a&gt;");
      }
      else if(i-nCurrIndex&gt;3&amp;&amp;flag1){
        flag1=false;
        document.write("&lt;a href=\"javascript:void(0)\" style=\"border:none\"&gt;...&lt;/a&gt;");
      }
      else if(nCurrIndex-i&gt;3&amp;&amp;flag2){
        flag2=false;
        document.write("&lt;a href=\"javascript:void(0)\" style=\"border:none\"&gt;...&lt;/a&gt;");
      }
    }
  
    // 3 输出下一页和尾页
    // 3.1 当前页是尾页
    if(nCurrIndex == (_nPageCount-1)){
      document.write("&lt;a  class=\"up\" href=\"javascript:void(0)\"  style=\"width:40px\"&gt;下一页&lt;/a&gt;&amp;nbsp;");
      //document.write("&lt;li&gt;&lt;a href=\""+_sPageName+"_" + (_nPageCount-1) + "."+_sPageExt+"\"&gt;尾页&lt;/a&gt;&lt;/li&gt;");
    }
    // 3.2 当前页不是尾页
    else{
      var nNextIndex = nCurrIndex + 1;
      var sPreFileExt = nPreIndex == 0 ? "" : ("_" + nPreIndex);
      document.write("&lt;a  class=\"up\" href=\""+_sPageName+"_" + nNextIndex + "."+_sPageExt+"\"  style=\"width:40px\"&gt;下一页&lt;/a&gt;&amp;nbsp;");
      //document.write("&lt;li&gt;&lt;a href=\""+_sPageName+"_" + (_nPageCount-1) + "."+_sPageExt+"\"&gt;尾页&lt;/a&gt;&lt;/li&gt;");
    }
  
  }
  
  createPageHTML(699, 0, "index", "html");
  &lt;/script&gt;
  </code></pre>
  
  <p>I don't know JS so I'm not really sure what this code is doing.
  I have no problem accessing all other portions of the page I want to scrape, only this one tag is giving me issues. This is only one of the Chinese sites I'm having trouble with, however, the English sources I'm scraping have given me no problems. I'm not sure if the issue is my inexperience in web scraping or if there's something funky that happens with Chinese sites.</p>
  
  <p>For reference, <a href="http://www.xizang.gov.cn/xwzx/qnyw/index.html" rel="nofollow noreferrer">http://www.xizang.gov.cn/xwzx/qnyw/index.html</a> is the webpage I'm trying to scrape. The button for navigating to the next page at the bottom is what's giving me trouble.</p>
  
  <p>Any advice or help would be greatly appreciated. Thanks!</p>